VBA - Message box if specific cell isn't populated

rachel06

Board Regular
Joined
Feb 3, 2016
Messages
84
Office Version
  1. 365
Platform
  1. Windows
Hello!

I have a macro that does something pretty simple - prints one sheet to PDF and saves another sheet in a new workbook. I've basically automated a payment workbook using a bunch of formulas, but one of the cells is a dropdown that must be manually populated.

I would like something at the very beginning of the code where a message box would pop up and essentially kill the macro if cell E2 is blank.
Code:
Sub CheckPmtType()

If Range("E2").Value = ”” Then MsgBox "Please select a payment type"

Else Call PrintToPDF

End Sub

I’m sure I just need to add something about exiting the sub after the if/then statement but I’m stuck.

Thank you!!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
The Else will not work if the entire IF...THEN is placed on one line.
Also, VBA does not like slanted double-quote marks like ”.

Try:
VBA Code:
Sub CheckPmtType()

If Range("E2").Value = "" Then
    MsgBox "Please select a payment type"
Else
    Call PrintToPDF
End If

End Sub
 
Upvote 1
Solution
The Else will not work if the entire IF...THEN is placed on one line.
Also, VBA does not like slanted double-quote marks like ”.

Try:
VBA Code:
Sub CheckPmtType()

If Range("E2").Value = "" Then
    MsgBox "Please select a payment type"
Else
    Call PrintToPDF
End If

End Sub

Works perfectly. Thanks so much!!
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 1

Forum statistics

Threads
1,215,109
Messages
6,123,136
Members
449,098
Latest member
Doanvanhieu

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