Do not run macro if multiple cells are empty?

NessPJ

Active Member
Joined
May 10, 2011
Messages
431
Office Version
  1. 365
Hi,

Right now i have a code preventing my Macro to run, if one of the used (required) cells are still empty.

Here is the code:
Code:
Sub Gegevens_Verwerken()
    If Range("C6") = Empty Then
    MsgBox "De Invoersheet is nog leeg of niet correct gevuld!", 64, "Gegevens niet verwerkt"
    Else
    Call Gegevens_Verwerken2
    End If
 
End Sub

I would want to change thise code to check if multiple cells are Empty.
(This would go for : C6 and G6...some of the cells in between will always be empty due to the layout so i would only need the code to look for those cells).

Any clues? :)

I tried using "IF AND(RANGE..." or "IF Array(..." but those kept giving me error messages.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Something like:
Rich (BB code):
Sub Gegevens_Verwerken()
    If Range("C6") = Empty Or Range("G6") = Empty Then
    MsgBox "De Invoersheet is nog leeg of niet correct gevuld!", 64, "Gegevens niet verwerkt"
    Else
    Call Gegevens_Verwerken2
    End If
    
End Sub
Or means if either C6 or G6 are empty
Change Or to And if you want both cells to be empty
 
Upvote 0
Hey,

Am i limited to a number of Cells i can use?

Right now i'm using several Cells using the "AND" statement, but its not working correctly:

Code:
Sub Gegevens_Verwerken()
    If Range("C6") = Empty And Range("D6") = Empty And Range("E6") = Empty And Range("G6") = Empty And Range("H6") = Empty And Range("I6") = Empty And Range("J6") = Empty Then
    MsgBox "De Invoersheet is nog leeg of niet correct gevuld!", 64, "Gegevens niet verwerkt"
    Else
    Call Gegevens_Verwerken2
    End If
 
End Sub
 
Upvote 0
Anyone else have an idea perhaps?
The Editor seems to accept the code without problems, yet it is not working the way it should.
 
Upvote 0
Problem solved. The syntax had to be slightly different:

Code:
Sub Gegevens_Verwerken()

    If (Range("C6") = Empty) Or (Range("E6") = Empty) Or (Range("G6") = Empty) Or (Range("J6") = Empty) Or (Range("C7") = Empty) Or (Range("E7") = Empty) Or (Range("G7") = Empty) Or (Range("J7") = Empty) Then
    MsgBox "De Invoersheet is nog leeg of niet correct gevuld!", 64, "Gegevens niet verwerkt"
    Else
    Call Gegevens_Verwerken2
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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