我在C列和D列中将值设置为常规格式。如果C和D列中单元格值介于0和9之间,VBA宏如何将格式更改为数字?基本上我想要0为0.00和9为9.00。
由于
答案 0 :(得分:2)
尝试一下:
Sub formatit()
Dim r As Range, N As Long
Set r = Intersect(ActiveSheet.UsedRange, Range("C:D"))
N = Cells(Rows.Count, "C").End(xlUp).Row
For i = 1 To N
cc = Cells(i, "C").Value
dd = Cells(i, "D").Value
If cc >= 0 And cc <= 9 And dd >= 0 And dd <= 9 Then
Range(Cells(i, "C"), Cells(i, "D")).NumberFormat = "0.00"
End If
Next i
End Sub
答案 1 :(得分:0)
是否特别需要VBA?否则conditional formatting应该可以帮助您实现目标。