Msgbox before macro is run

Alpacino

Well-known Member
Joined
Mar 16, 2011
Messages
511
I like to display a msgbox " you must enter figured before running macro" if range C4:O6 is blank and the user tries clicking on rectangle1 which has a macro assigned to it.
Sheet is called "budgets"
Thanks in advance :)
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Assuming you want to ensure that no cell in the range C4:O6 is blank:
Code:
Sub test()
For Each c In Range("C4:O6")
    If IsEmpty(c) Then
        MsgBox "enter figures before running this macro"
    Exit Sub
    End If
Next c
'rest of macro
End Sub
Note that this will not stop the macro from running if all cells in the range have a formula in them which returns "" (null string).
 
Upvote 0
Nice thank you.
Is there a way to show in msgbox which cell which row is empty for Eg
Row 4 is sales
Row 5 is waste
Row 6 is wages
Msgbox "wages needs completing"
:)
 
Upvote 0
Code:
Sub test()
For Each c In Range("C4:O6")
    If IsEmpty(c) Then
        Select Case c.Row
        Case Is = 4
            MsgBox "sales needs completing"
            c.Select
            Exit Sub
        Case Is = 5
            MsgBox "waste needs completing"
            c.Select
            Exit Sub
        Case Is = 6
            MsgBox "wages needs completing"
            c.Select
            Exit Sub
        End Select
    End If
Next c
'rest of macro
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,254
Members
452,900
Latest member
LisaGo

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