If You want to check blank cell or empty cell in particular range through excel vba. You can check out this vba code. You can find out how many cells are empty in the range
Sub vba_check_empty_cells()
Dim i As Long
Dim c As Long
Dim myRange As Range
Dim myCell As Range
' now set your range from where you want to find out empty cell
Set myRange = Range("A1:A10")
' now use loop function to find out cell value
For Each myCell In myRange
c = c + 1
If IsEmpty(myCell) Then
i = i + 1
End If
Next myCell
MsgBox "There are total " & i & " empty cell(s) out of " & c & "."
End Sub
If you want to check only empty cell, not the number of empty cell and If You want to stop to run the vba code while there are empty cell exist, then use below code...
Sub vba_check_empty_cells()
Dim myRange As Range
Dim myCell As Range
' now set your range from where you want to find out empty cell
Set myRange = Range("A1:A10")
' now use loop function to find out cell value
For Each myCell In myRange
If IsEmpty(myCell) Then
MsgBox "You should fill all the cell from Range(A1:A10)"
Exit Sub
End If
Next myCell
End Sub
If You want to check blank cell for Table's Columns or through name range. Here create your range through name range first. Here I already created the range as myRange. First select the range and goto Formulas Tab >> Name Manager >> New >> type name >> Ok and then write the below vba code.
Dim c As Range
For Each c In Range("myRange")
If c.Value = "" Then
MsgBox "Please Fill all the cells"
Exit Sub
End If
Next c
If you wish to visit my channel then click here
No comments:
Post a Comment