VBA Message Box if Cell Blank

srj1359

New Member
Joined
Mar 5, 2015
Messages
46
Office Version
  1. 2016
Platform
  1. Windows
Hello there!

Can someone please help me create a VBA code for a message box to appear if cell O16 has been left blank?

This is part of a larger macro to transfer data from the tab "Pricing Sheet" onto a tab called "Quote Summary" so I am wanting to put this coding at the very beginning and then if cell O16 is blank, the macro stops, and if it is not blank, it can proceed and copy all data as it is supposed to.

Thank you in advance!!

Here is what I have right now:

'message box for blank start date
With Sheets("Pricing Sheet")
If .Range("O16") = "" Then
.Select
.Range("O16").Select
MsgBox "Please enter the start date in cell O16"
Cancel = True
End If
End With
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Maybe something like
VBA Code:
With Sheets("Pricing Sheet")
If .Range("O16") = "" Then
MsgBox "Please enter the start date in cell O16"
Sheets("Pricing Sheet").Activate
.Range("O16").Select
End If
End With
 
Upvote 0
Typo
VBA Code:
Sub MM1()
With Sheets("Pricing Sheet")
    If .Range("O16") = "" Then
        MsgBox "Please enter the start date in cell O16"
        .Activate
        .Range("O16").Select
    End If
End With
End Sub
 
Upvote 0
@Michael M thank you very much for your quick reply!

The message box is appearing as it should, but it's not halting the entire VBA at that point if the cell is blank. Is that possible to do?
 
Upvote 0
Ok, sorry...
But keep in mind, if you have any disableevents = false OR sceenupdating =false they need to be returned to TRUE before the Exit Sub line
VBA Code:
Sub MM1()
With Sheets("Pricing Sheet")
    If .Range("O16") = "" Then
        MsgBox "Please enter the start date in cell O16"
        .Activate
        .Range("O16").Select
       Exit Sub
    End If
End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,957
Latest member
Hat4Life

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