Message Box Help - Basics

rjbinney

Active Member
Joined
Dec 20, 2010
Messages
279
Office Version
  1. 365
Platform
  1. Windows
I need to write a macro that inserts a row, and some formulas, BELOW a specific row.

Since the "Insert Row" command adds a row ABOVE the selected row, I would like to:
1) Have a button that says "Insert Row"
2) Have a message box pop up that says something to the effect of, "Make sure you have selected a cell in the correct row", with the options something like, "OK - Go ahead" or "Whoops - Cancel"
3) Then, when they click "OK - Go ahead", it runs the macro.

I've Googled message boxes, and I see the VBA code.

What I don't know is, what actually triggers the display of the message box?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
The Click() event of the button ought to trigger the display of the message box ;eg

Code:
Sub Insert Row_Click()
    MsgBox "Make sure you have selected a cell in the correct row", vbOKCancel, "Go ahead / Cancel ?"

End Sub



I need to write a macro that inserts a row, and some formulas, BELOW a specific row.

Since the "Insert Row" command adds a row ABOVE the selected row, I would like to:
1) Have a button that says "Insert Row"
2) Have a message box pop up that says something to the effect of, "Make sure you have selected a cell in the correct row", with the options something like, "OK - Go ahead" or "Whoops - Cancel"
3) Then, when they click "OK - Go ahead", it runs the macro.

I've Googled message boxes, and I see the VBA code.

What I don't know is, what actually triggers the display of the message box?
 
Upvote 0
Maybe something like
Code:
Sub MM1()
Dim ar As Range
Set ar = Application.InputBox("Please Select a cell to Insert a row", "Insert Row", Type:=8)
Rows(ar.Offset(-1, 0).Row).Insert
End Sub
 
Upvote 0
Thanks, both.

Reggie - Whether or not I hit "OK" or "Cancel", it inserts the row anyway.

Michael - what does "Type:=8" mean?
 
Upvote 0
Code:
Sub Insert Row_Click()
    MsgBox "Make sure you have selected a cell in the correct row", vbOKCancel, "Go ahead / Cancel ?"


    'you will have to 'tell' the macro what to do when the user clicks on either "OK" or "CANCEL" 
    'eg; 
    
     if vbYes then
        ' Do this
     elseif vbCancel then
        ' Do something else 
     end if
		
End Sub

Thanks, both.

Reggie - Whether or not I hit "OK" or "Cancel", it inserts the row anyway.

Michael - what does "Type:=8" mean?
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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