答案 0 :(得分:1)
此宏在两种颜色之间交替变换,当A列中的值发生变化时会发生变化。
Sub Highlighting()
Dim rw As Long
Dim lastrw As Long
' Define 2 different highlighting colours by their RGB values
Dim col1 As Long
Dim col2 As Long
col1 = RGB(255, 230, 180)
col2 = RGB(180, 230, 255)
' "Current" colour for highlighting
Dim col As Long
col = col1
With ThisWorkbook.ActiveSheet
' Get last row by last non-empty cell in column A
lastrw = .Cells(.Rows.Count, 1).End(xlUp).Row
' Cycle through column A
For rw = 1 To lastrw
' Highlight row with current colour
.Range("A" & rw & ":G" & rw).Interior.Color = col
' If column A value in next row is different, change colour
If .Cells(rw + 1, 1).Value <> .Cells(rw, 1) Then
' Set to whichever colour it is not
If col = col1 Then
col = col2
Else
col = col1
End If
End If
Next rw
End With
End Sub
在:
后:
在某些情况下,您可以通过将自己的条件If .Range("F" & rw).Value = "Files ... "
等插入主For
循环来将字体颜色更改为红色。