VBA - validating data before proceeding

s_whitie

Board Regular
Joined
Sep 13, 2007
Messages
96
Hi

I have the following routine to print from my worksheet:

Sheets("BACS Ltr").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Data Input").Select
Range("C5").Select

What I want is that if the user has not entered data into the following fields then the process should stop and a message displayed to advise the user:

"Please complete all data before proceeding"

Fields to be completed (all in sheet "Data Input")
C5
C18
C19
C27
G29

Can anyone help? Thanks
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You could put
Code:
IF Application.Countblank(Range("C5,C18,C19,C27,G29")) = 5 Then
    MsgBox "Please Complete..."
    Exit Sub
End If
 
continue code

Hope this helps..
 
Upvote 0
Thanks

So now I have

If Application.CountBlank(Range("C5,C18,C19,C27,G29")) = 5 Then
MsgBox "Please Complete..."
Exit Sub
End If
Sheets("BACS Ltr").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("Data Input").Select
Range("C5").Select
End Sub

But this is giving me an error - Run Time error '13' Type mismatch??
 
Upvote 0
Wait, countblank didn't work the way I thought it would. It errors..

try this instead

Code:
Sub Test()
Dim myrange
Dim C As Range
Set myrange = Range("C5,C18,C19,C27,G29")
For Each C In myrange
    If Len(C) = 0 Then
        MsgBox "Please complete.."
        Exit Sub
    End If
Next C
Continue Code
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,411
Messages
6,119,360
Members
448,888
Latest member
Arle8907

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