gpt4 book ai didi

vba - 跳过循环中的空单元格

转载 作者:行者123 更新时间:2023-12-03 03:37:49 26 4
gpt4 key购买 nike

我有下面的宏,它应该突出显示sheet2中与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

最佳答案

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

关于vba - 跳过循环中的空单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42924750/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com