我想找到“平均”:
Cells.Find(What:="Average", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
假设它在A5中找到。我正在寻找一种方法
PS:A5和A6右侧的所有单元格都是数字。
答案 0 :(得分:1)
我为您编写了代码,但是我没有循环。
为什么我没有循环?因此,您可以创建循环并在vba中变得更好,如果我为您完成了所有工作,它不会帮助您提高技能,好吗?希望你喜欢我的朋友!
Public Sub PaintValues()
Dim cl As Range
Dim clOnRight As Range
Dim clOnRightBelow As Range
Set cl = Cells.Find(What:="Average", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If cl Is Nothing Then
MsgBox "Average not found in this sheet!", vbExclamation, "Error!"
Exit Sub
End If
'Get the left cell of Cl (Average)
Set clOnRight = cl.Offset(0, 1)
Set clOnRightBelow = cl.Offset(1, 1)
If clOnRightBelow > clOnRight Then
clOnRightBelow.Interior.Color = vbBlue
ElseIf clOnRightBelow = clOnRight Then
clOnRightBelow.Interior.Color = VBA.RGB(122, 122, 122)
ElseIf clOnRightBelow < clOnRight Then
clOnRightBelow.Interior.Color = vbRed
End If
End Sub