VBA error - check to see if cell is empty

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
741
Office Version
  1. 365
Platform
  1. Windows
Good Morning

I was wondering how would i write a VBA that checks to see if there are any empty cells before it moves on with the macro.

Im looking for if D10 ( Jason Fletcher ) is not empty then check to see if E10, F10, G10, H10, I10, L10 are filled in, as so in for rows 11 to 24
then if frm D12 if the whole row is empty move on.

if there is an error create a message box
MsgBox "All field need to be filled in on the form?", vbOKOnly

hope im making sence

many thanks Jason

1649582917442.png
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I wouldn't use VBA. I would use conditional formatting to highlight cells that need to be filled in.

The condition for cell E10, for example, would be =AND(LEN($D10)>0,LEN(E10)=0)
 
Upvote 0
Jon's suggestion is the way to go but if you actually need a macro, try:
VBA Code:
Sub CheckEmptyCells()
    Application.ScreenUpdating = False
    Dim LastRow As Long, rng As Range, srcRng As Range
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For Each rng In Range("D10:D24")
        If rng <> "" Then
            Set srcRng = Union(Range("E" & rng.Row & ":I" & rng.Row), Range("L" & rng.Row))
            If WorksheetFunction.CountA(srcRng) = 0 Then
                MsgBox ("All fields need to be filled in on the form in row " & rng.Row & "."), vbOKOnly
                Exit Sub
            End If
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top