我正在尝试在两列(e和f)中自动搜索空白单元格。我的目标是在一个消息框中显示这些空白单元格的地址。如果没有空白单元格,则会出现一个消息框,提示在两列中找不到空白单元格。到目前为止,我已经尝试了代码,但这只适用于第5(e)列,并且没有验证如果没有空白单元格,它将提示一条消息。我不知道如何才能继续实现我的目标。
下面是我目前尝试的代码:
Sub test()
Dim i As Long, lastrow As Long
Dim rng As Range
Dim MsgStr As String
Dim c As Range
lastrow = Cells(Rows.Count, "E").End(xlUp).Row
For i = 2 To lastrow
If Cells(i, 5) = "" Then
If MsgStr = "" Then
MsgStr = Cells(i, 5).Address(False, False)
Else
MsgStr = MsgStr & "," & Cells(i, 5).Address(False, False)
End If
End If
Next i
MsgBox MsgStr & " cells are empty"
End Sub