我一直在尝试创建一个vba代码,以检查在所选单元格的每个范围内是否有2个条件。如果两个条件都满足,我想给它上色。我是这样写的:
Dim ThisRng As Range
Set ThisRng = Application.InputBox("Select a range", "Get Range", Type:=8)
Selection.Activate
Dim cel As Range
For Each cel In ThisRng.Cells
With cel
cel.Find("..condition1 to search").Activate
ActiveCell.Find("...secondcondition").Activate
ActiveCell.Select
ActiveCell.Interior.ColorIndex = 33
ThisRng.Activate
End With
Next cel
仅当条件为真时才有效。如果无法激活单元格,它会给我一个错误,并且不会移动到下一个单元格。
请问任何想法?
由于
答案 0 :(得分:0)
这将为具有圆形公式结束“0”“
的任何单元格颜色着色Sub Demo
Dim ThisRng As Range
Set ThisRng = Application.InputBox("Select a range", "Get Range", Type:=8)
Dim cel As Range
For Each cel In ThisRng.Cells
if len(cel.formula)>6 then
if left(cel.formula,6)="=ROUND" and right(cel.formula,3) = ",0)" then
cel.interior.ColorIndex = 3
end if
end if
next cel
End Sub