自定义格式宏:需要打印带小数点的个位数整数



我正在开发一个小宏,将文件输出为prn,该prn将用作其他软件的输入。我已经让一切正常工作,唯一的问题是其他软件要求所有整数都用小数点打印。

使用excel 2007 btw

如果单元格值为0,则应打印为"0",而不是空白。同样,如果值是8,它应该打印为"8"。这对大多数值来说都不是问题,因为绝大多数值都像123.45765等。

代码告诉我它在第4行上.NumberFormat("0.")中的小数点后期望a

Windows("bdf_generator").Activate
With Worksheets(2).Range("E2:H9592").FormatConditions _
.Add(xlCellValue, xlBetween, "=0", "=9")
FormatConditions(1).NumberFormat=(""0."")
With Selection.FormatConditions(1).StopIfTrue = False
End With
End With

在您的例子中,由于0.周围有两个双引号(""),所以行FormatConditions(1).NumberFormat=(""0."")不正确。还要注意,FormatConditions(1).NumberFormat = "0."应该以Selection.为前缀,否则会在运行时引发错误。试试这个,因为我相信它更清楚(你会得到智能感知):

Windows("bdf_generator").Activate
Dim r As Excel.Range
Set r = Worksheets(2).Range("E2:H9592")
Dim fc As Excel.FormatCondition
Set fc = r.FormatConditions.Add(xlCellValue, xlBetween, "=0", "=9")
fc.NumberFormat = "0."
fc.StopIfTrue = False

最新更新