我有这个 VBA 代码:
Private Sub Worksheet_Activate()
Sheet1.Cells(10, 10).Select
Range("$B$2:$E$7").FormatConditions.Delete
With Range("$B$2:$E$7").FormatConditions.Add(Type:=xlExpression, Formula1:="=$G2=""Yes""")
.Interior.Color = RGB(150, 100, 0)
End With
Debug.Print "Formula is wrong : " & Range("$B$2:$E$7").FormatConditions(1).Formula1
Range("$B$2:$E$7").Select
Range("$B$2:$E$7").FormatConditions.Delete
With Range("rngDatesLockedRange").FormatConditions.Add(Type:=xlExpression, Formula1:="=$G2=""Yes""")
.Interior.Color = RGB(150, 100, 0)
End With
Debug.Print "Formula is correct : " & Range("$B$2:$E$7").FormatConditions(1).Formula1
End Sub
调试跟踪显示:
Formula is wrong : =$G1048570="Yes"
Formula is correct : =$G2="Yes"
为什么在将格式应用于该范围之前不选择范围时它不起作用?在 Excel 2010 中,这工作正常吗?