2
我想颜色突出显示彼此不同的单元格;在这种情况下colA和colB。该功能适用于我所需要的功能,但看起来反复,丑陋,效率低下。我不熟悉VBA编码;有没有更优雅的书写这个功能的方法?VBA宏来比较两列和颜色突出显示单元格区别
编辑 我试图让这个功能做的是:1。 亮点细胞可乐具有不同或不COLB 2.亮点细胞COLB具有不同或不可乐
Sub compare_cols()
Dim myRng As Range
Dim lastCell As Long
'Get the last row
Dim lastRow As Integer
lastRow = ActiveSheet.UsedRange.Rows.Count
'Debug.Print "Last Row is " & lastRow
Dim c As Range
Dim d As Range
Application.ScreenUpdating = False
For Each c In Worksheets("Sheet1").Range("A2:A" & lastRow).Cells
For Each d In Worksheets("Sheet1").Range("B2:B" & lastRow).Cells
c.Interior.Color = vbRed
If (InStr(1, d, c, 1) > 0) Then
c.Interior.Color = vbWhite
Exit For
End If
Next
Next
For Each c In Worksheets("Sheet1").Range("B2:B" & lastRow).Cells
For Each d In Worksheets("Sheet1").Range("A2:A" & lastRow).Cells
c.Interior.Color = vbRed
If (InStr(1, d, c, 1) > 0) Then
c.Interior.Color = vbWhite
Exit For
End If
Next
Next
Application.ScreenUpdating = True
End Sub
如何彻底摆脱VBA,并使用XL强大的'Conditional Formatting'功能?此外,也许这更适合[代码评论](http://codereview.stackexchange.com/) –
@ScottHoltzman所有版本都可以使用该功能吗? – Kermit
@njk - >好问题。虽然如此,但07/10赛季的功能比03更强劲,但我不确定07/10赛季的差距,尽管如此,我的头脑还是不错。 –