我有一列中包含不同的數字。我的代碼正在對它們進行排序,並將檢查相同編號在該列中出現的頻率。如果一個值出現超過3次,則應該爲包含該值的所有行着色,否則應該刪除行。循環遍歷單元格範圍,如果某個值在該範圍內超過3次,則更改顏色
這裏是我到目前爲止的代碼:
Sub mySub10()
Dim wsTEMP As Worksheet
Dim wsSPECIAL As Worksheet
Dim wsTEMPLrow As Long
Dim i As Integer
Dim x As Integer
Dim rng As Range
Set wsTEMP = ThisWorkbook.Sheets("Temp")
Set wsSPECIAL = ThisWorkbook.Sheets("Spezial")
Application.ScreenUpdating = False
wsTEMPLrow = Worksheets("Temp").Range("A" & Worksheets("Temp").Rows.Count).End(xlUp).Row
With wsTEMP
.Columns("A:Q").Sort Key1:=.Range("L1"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
For i = wsTEMPLrow To 5 Step -1
Set rng = Range("A" & i)
If Cells(i, 12).Value = Cells(i - 1, 12).Value And Cells(i, 12).Value = Cells(i - 2, 12).Value And Cells(i, 12).Value = Cells(i - 3, 12).Value And Cells(i, 12).Value = Cells(i - 4, 12).Value Then
Range("A" & i).EntireRow.Interior.ColorIndex = 6
Range("A" & i - 1).EntireRow.Interior.ColorIndex = 6
End If
Next
For i = wsTEMPLrow To 2 Step -1
Set rng = Range("A" & i)
If rng.Interior.ColorIndex <> 6 Then
rng.EntireRow.Delete
End If
Next
End With
End Sub
什麼是你的代碼的問題? –