Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba Excel中的小数点问题_Vba_Excel - Fatal编程技术网

Vba Excel中的小数点问题

Vba Excel中的小数点问题,vba,excel,Vba,Excel,我正在尝试使用VBA在单元格中放置一个小数点后两位的数字,后跟单元格中括号内的文本,例如: 1.23(案文) 我如何实现这一目标的示例如下: Cells(1, 1) = 1.23 Cells(1, 2) = Cells(1, 1) & " (text)" 单元格(1,1)的格式为工作表上的两位小数,但如果该数字为1.20或1.00,例如,结果为: 1.2(文本)或1(文本) 如何将单元格(1,2)中的两个小数位强制保持为两个小数位?我试过: Cells(1, 2) = Round(Ce

我正在尝试使用VBA在单元格中放置一个小数点后两位的数字,后跟单元格中括号内的文本,例如:

1.23(案文)

我如何实现这一目标的示例如下:

Cells(1, 1) = 1.23
Cells(1, 2) = Cells(1, 1) & " (text)"
单元格(1,1)的格式为工作表上的两位小数,但如果该数字为1.20或1.00,例如,结果为:

1.2(文本)或1(文本)

如何将单元格(1,2)中的两个小数位强制保持为两个小数位?我试过:

Cells(1, 2) = Round(Cells(1, 1), 2) & " (text)"

Cells(1, 1).NumberFormat = "0.00"
Cells(1, 2) = Cells(1, 1) & " (text)"
但这两种方法都不管用。有什么建议吗?

您可以使用:

或者,您可以直接将数字格式应用于单元格,而不是将其转换为文本值。在“单元格编号格式”属性中,使用以下格式:

0.00“(文本)”-0.00“(其他文本);“0.00”

只要它允许,我就这么做:)
Cells(1,2) = Format(Cells(1,1), "0.00") & "(text)"