我正在尝试编写一个宏来检查 Excel 电子表格中的某个列,以查找小于 9 个字符但大于 2 个字符的条目,如果找到,则显示一条消息并突出显示找到该值的单元格。它可能会发生多次。我写了以下代码:
Sub Highlight()
Dim c As Range
Dim LR As Integer
Dim intCell As Long
LR = Worksheets("Basket").Cells(Rows.Count, 6).End(xlUp).Row
For intCell = 1 To 8
For Each c In Range("G20:G" & LR).Cells
If Len(c.Value) < 9 And Len(c.Value) > 2 Then
MsgBox "One or more of the codes is invalid. Correct the highlighted values."
c.Cells(intCell).Interior.Color = vbYellow
End If
Next
Next
End Sub
我无法弄清楚我做错了什么。任何帮助将不胜感激。