Required fields in a form

NFournier

New Member
Joined
Feb 7, 2018
Messages
6
Hello,

I'm trying to create a form that cannot be printed unless certain fields are filled in (A1, B19 & B45).

Been using VBA and found this online:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Sheets("Cover Sheet").Range("A1,B19,B45").Value = "" Then
Cancel = True
MsgBox ("Please complete all required fields prior to printing.")
End If
End Sub

If works, however it only works if A1 is not filled in.

Any help you can provide would be greatly appreciated.

Thank you.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Code:
With Sheets("Cover Sheet")
    If (.Range("A1").Value = vbNullString) or  (.Range("B19").Value = vbNullString) or (.Range("B45").Value = vbNullString) Then
 
Upvote 0
Thank you for the quick reply.

What I have now is:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
With Sheets("Cover Sheet")
If (.Range("A1").Value = vbNullString) Or (.Range("B19").Value = vbNullString) Or (.Range("B45").Value = vbNullString) Then
Cancel = True
MsgBox ("Please complete all required fields prior to printing.")
End If
End Sub

I'm getting an error message now stating that:

Compile Error:
Expected End With

Sorry I am very new to VBA so I'm still trying to figure all this out...
 
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,794
Members
448,994
Latest member
rohitsomani

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