|
|
Sub cccccc()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
' 定义橙黄色(匹配常见的高亮橙黄,RGB值可微调)
Dim orangeColor As Long: orangeColor = RGB(255, 204, 0)
' ===== 自定义参数(仅需改这里)=====
Set ws = ThisWorkbook.Sheets("A") ' 替换为你的工作表名(如"数据")
' ==================================
On Error GoTo ErrorHandler
' 找到K列最后一行有数据的行号(避免漏行)
lastRow = ws.Cells(ws.Rows.Count, "K").End(xlUp).Row
If lastRow < 2 Then
MsgBox "K列无有效数据!", vbExclamation
Exit Sub
End If
' 先清除K/L列原有填充色(避免残留旧颜色)
ws.Range("K2:L" & lastRow).Interior.Color = xlNone
' 遍历每行,比较K/L列数据并标色
For i = 2 To lastRow
' 排除空值:仅当K/L列都非空且值相等时标色
If ws.Cells(i, "K").Value <> "" And ws.Cells(i, "L").Value <> "" Then
If ws.Cells(i, "K").Value = ws.Cells(i, "L").Value Then
' 给当前行K、L列单元格标橙黄色
ws.Range("K" & i & ":L" & i).Interior.Color = orangeColor
End If
End If
Next i
MsgBox "标注完成!已将K/L列数据相同的单元格标为橙黄色", vbInformation
Exit Sub
ErrorHandler:
MsgBox "标注出错:" & Err.Description, vbCritical
End Sub
|
|