跳过循环中的空单元格

我有下面的macros应该高亮表单2中的单元格与sheet1中的单元格不同。 它运行良好,但突出显示空白单元格有问题:

Private Sub Compare() Dim shtARng As Range, cell As Range With Worksheets("Sheet1") Set shtARng = .Range("A1", .Cells(.Rows.Count, 1).End(xlUp)) End With With Worksheets("Sheet2") For Each cell In .Range("C2", .Cells(.Rows.Count, 9).End(xlUp)) If shtARng.Find(What:=cell.Value, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False) Is Nothing Then cell.Interior.ColorIndex = 3 Next cell End With End Sub 

使用IsEmpty检查单元格是否为空。 如果不是空的,那么做突出显示,否则循环到下一个单元格。

 For Each cell In .Range("C2", .Cells(.Rows.Count, 9).End(xlUp)) If Not IsEmpty(cell) Then If shtARng.Find(What:=cell.Value, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False) Is Nothing Then cell.Interior.ColorIndex = 3 End If End If Next cell 
 Private Sub Compare() Dim shtARng As Range, cell As Range With Worksheets("Sheet1") Set shtARng = .Range("A1", .Cells(.Rows.Count, 1).End(xlUp)) End With With Worksheets("Sheet2") For Each cell In .Range("C2", .Cells(.Rows.Count, 9).End(xlUp)) 'Only Proceed If The Length Of The Cell Is Bigger Than Zero If Len(cell) > 0 Then If shtARng.Find(What:=cell.Value, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False) Is Nothing Then cell.Interior.ColorIndex = 3 End If Next cell End With End Sub