vba检查负值

Tru*_*ran 0 excel vba excel-vba negative-number

我写了一个简单的VBA代码来检查单元格的值是否为负数,如果是负数,则将其突出显示为红色.出于某种原因,我不断遇到"运行时不匹配".我的代码是

For x = 2 To 100

Set val3 = Worksheets("Summary").Cells(x, 9)
If val3.Value < 0 Then
Worksheets("Summary").Cells(x, 9).FontColorIndex = 3

End If
Next x
Run Code Online (Sandbox Code Playgroud)

第9列(我正在检查的列)中填充了美元值.预先感谢您的帮助.

小智 6

在你的代码中,你只是错过了一个点.

FontColorIndex = 3

应该:

Font.ColorIndex = 3