I'm trying to automate the search of blank cells in two columns(E and F). My goal is to display the address of these blank cells in one message box. And if there is no blank cell then a message box prompting that there are no blank cells found in two columns. I have tried the code so far but this only works for 5th(E) column and no validation that if there is no blank cell it will prompt a message. I am not sure anymore on how I can proceed to achieve my goal for this.
Below is the code I tried so far:
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
Try SpecialCells(xlCellTypeBlanks) .
Sub test()
Dim lastrow As Long, rng As Range
Dim MsgStr As String
lastrow = Cells(Rows.Count, "E").End(xlUp).Row
on error resume next
set rng = range(cells(2, "E"), cells(lastrow, "F")).specialcells(xlcelltypeblanks)
on error goto 0
if not rng is nothing then
msgbox rng.address(0,0) & " are blank"
else
msgbox "no blank cells"
end if
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.