我有两列J和L。
如果J列的值与L列的对应值匹配,则两个单元格都应突出显示为红色。
我是这个Excel的新手。我无法开发此宏。
我尝试了以下代码,但是如果匹配,它将突出显示J,K和L列,我只希望突出显示J和K列,并且此宏也应从J11和L11开始检查。
Sub test()
Dim LastRow As Long, i As Long
Dim arr As Variant
With ThisWorkbook.Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "J").End(xlUp).Row
arr = .Range("J2" & ":L" & LastRow)
For i = LBound(arr) To UBound(arr)
If arr(i, 1) = arr(i, 3) Then
.Range("J" & i + 1 & ":L" & i + 1).Interior.Color = vbRed
End If
Next i
End With
End Sub
答案 0 :(得分:2)
检查这是否是您想要的
Sub test()
Dim LastRow As Long, i As Long
Dim arr As Variant
With ThisWorkbook.Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "J").End(xlUp).Row
arr = .Range("J11" & ":L" & LastRow)
For i = LBound(arr) To UBound(arr)
If arr(i, 1) = arr(i, 3) Then
.Range("J" & i + 10 & ":J" & i + 10).Interior.Color = vbRed
.Range("L" & i + 10 & ":L" & i + 10).Interior.Color = vbRed
End If
Next i
End With
End Sub
它从第11行开始检查
答案 1 :(得分:0)
我认为这是期望的输出:
Sub test()
Dim LastRow As Long, i As Long
Dim arr As Variant
With ThisWorkbook.Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "J").End(xlUp).Row
arr = .Range("J2" & ":L" & LastRow)
For i = LBound(arr) To UBound(arr)
If arr(i, 1) = arr(i, 3) Then
.Range("J" & i + 1).Interior.Color = vbRed
.Range("L" & i + 1).Interior.Color = vbRed
End If
Next i
End With
End Sub
只需将它们分开。
答案 2 :(得分:0)