Jea*_*FIC 0 excel vba excel-vba excel-formula
我想知道是否有办法使用VBA执行以下操作:如果宏在列B中找到单词"Total",那么total的颜色的内部颜色将以蓝色着色,并且它用于B列中的所有"总计"单词.注意:我有不同的总数...它不仅仅是"总计"这个词
就像这样(即从col A到F的颜色)
我试过这个,但它没有正常工作,代码很糟糕......
Sub forme_couleur()
Dim myRow As Integer
myRow = 1
While Not IsEmpty(Cells(myRow, 2))
If Cells(myRow, 2).Find(What:="Total") Is Nothing Then
myRow = myRow + 1
Else
Cells(myRow, 2).Find(What:="Total").Interior.Color = RGB(174, 240, 194)
End If
myRow = myRow + 1
Wend
End Sub
Run Code Online (Sandbox Code Playgroud)
考虑:
Sub ColorMeBlue()
Dim i As Long, N As Long, s As String
N = Cells(Rows.Count, "B").End(xlUp).Row
s = "Total"
For i = 1 To N
If InStr(1, Cells(i, 2).Value, s) > 0 Then
Range("A" & i & ":F" & i).Interior.Color = RGB(174, 240, 194)
End If
Next i
End Sub
Run Code Online (Sandbox Code Playgroud)
编辑#1:
要按编号使用列引用范围,请使用:
Sub ColorMeBlue2()
Dim i As Long, N As Long, s As String
N = Cells(Rows.Count, "B").End(xlUp).Row
s = "Total"
Firstcol = 1
LastCol = 6
For i = 1 To N
If InStr(1, Cells(i, 2).Value, s) > 0 Then
Range(Cells(i, Firstcol), Cells(i, LastCol)).Interior.Color = RGB(174, 240, 194)
End If
Next i
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72 次 |
| 最近记录: |