我想突出顯示單元格,當有3個或更多具有相同的值時,我有下面的代碼,但它不能正常工作,因爲它循環兩次到每個範圍。有人能告訴我什麼是錯的嗎?通過過濾範圍循環excel vba
Sub HighlightCells()
Dim k As Integer, myCounter As Integer, firstRow As Integer
Dim myClientExport As Worksheet, myTemplate As Variant
Dim vRange As Range, myRange As Range
Dim myAddr As String
Set myClientExport = Excel.ActiveSheet
Set vRange = myClientExport.UsedRange.SpecialCells(xlCellTypeVisible)
firstRow = vRange.Areas(2).Rows(1).Row
myAddr = Cells(firstRow, 4).Value
myCounter = 0
For Each myRange In vRange.Rows
k = myRange.Row
If k > firstRow Then
If myAddr = Cells(k, 4).Value Then
myCounter = myCounter + 1
Else
myAddr = Cells(k, 4).Value
myCounter = 0
End If
Select Case myCounter
Case 3
For i = 0 To 2
OId = Cells(k - i, 1).Value
Next i
Cells(k, 4).Interior.ColorIndex = 27
Cells(k - 1, 4).Interior.ColorIndex = 27
Cells(k - 2, 4).Interior.ColorIndex = 27
Case Is > 3
Cells(k, 4).Interior.ColorIndex = 27
End Select
End If
Next myRange
End Sub
我想強調有3個或更多激活指令狀態的所有地址。
你可能需要添加它如何您的數據(過濾,過濾的)看起來像 – user3598756
很難按照你的邏輯代碼的一些例子,請加載數據的屏幕截圖樣本和期望的結果 –
謝謝你,我只是添加了未經過濾和過濾的可能數據樣本。 – Luisxv