我需要帮助VBA中的Or语句。我有一个条件格式设置,如果一个单元格突出显示红色或橙色,阻止保存。
For Each rng In Worksheets(1).UsedRange
If rng.DisplayFormat.Interior.Color = vbRed Or rng.DisplayFormat.Interior.Color = #FF9900 Then 'This is where the code is erroring, may be I'm not referring to the color correctly.
MsgBox ("Please correct any fields highlighted in red")
Cancel = True
Application.ScreenUpdating = True
Exit Sub
End If
Next rng
谢谢!
答案 0 :(得分:1)
删除.DisplayFormat
Sub test()
Dim Rng as Range
For Each Rng In Worksheets(1).UsedRange
If Rng.Interior.Color = vbRed Or Rng.Interior.Color = 49407 Then
MsgBox ("Please correct any fields highlighted in red")
Cancel = True
Application.ScreenUpdating = True
Exit Sub
End If
Next Rng
End Sub