當前有一個連接到按鈕的模塊的Excel文檔。掃描並比較兩行
Excel文檔類似於下面:
ROW | COLUMN C | COLUMN K
1 808 253
2 808 256
3 908 355
4 908 355
5 908 356
6 907 253
7 907 253
當我點擊該按鈕下面的模塊揭開序幕:
Sub scan()
Dim dataRange As Range
Dim dataRange2 As Range
Dim oneCell As Range
Dim oneCell2 As Range
With ThisWorkbook.Sheets("Resource Info").Range("C:C")
Set dataRange = Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
End With
With ThisWorkbook.Sheets("Resource Info").Range("K:K")
Set dataRange2 = Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
End With
For Each oneCell In dataRange
If Application.WorksheetFunction.CountIf(dataRange, oneCell) > 1 Then
For Each oneCell2 In dataRange2
If Application.WorksheetFunction.CountIf(dataRange, oneCell) > 1 And Application.WorksheetFunction.CountIf(dataRange2, oneCell2) <> 1 Then
With oneCell
.EntireRow.Interior.ColorIndex = 6
End With
End If
Next oneCell2
End If
Next oneCell
End Sub
我想只有行1,2,3, 4,5列自C欄匹配後突出顯示,但列K數據與列C分組不匹配。
當前模塊我有亮點的所有行不管包含在列K.
(快速筆記,你還需要添加'使用前.''範圍()'在'With'語句) – BruceWayne
你能詳細分組的標準是什麼?而不是宏,你可以使用[條件格式](http://www.excel-easy.com/data-analysis/conditional-formatting.html)或[sumproduct](https:// exceljet)。 net/excel-functions/excel-sumproduct-function) – Alex
分欄應該發生在列C上。在該組中(即匹配數字),如果列K包含兩個不同的值,那麼應突出顯示該組中的行。希望能更好地解釋。 – Alex