2 Macro on 1 button

renman27

New Member
Joined
Dec 19, 2018
Messages
16
Hello, new to VBA. I have created a Record Macro to delete some formatting on my spreadsheet. It works fine with the button. I have had users use the clear button by accident...

I want to have a message box appear with "are you sure you want to clear" MsgBox "Ok to clear the schedule?", vbYesNo

But when I do this...

Only one works? It will still clear it...but the message will not appear. I have done seperatly and both work. so I added this to have both appear.



Sub Button1_Click()
Call Sub MsgBoxYesNo()
MsgBox "Are you sure you want to clear the sheet?", vbYesNo
End Sub'Macro1
Call 'Sub Test()
'
' Test Macro
'


'
Range("B22:M34").Select
Selection.Copy
ActiveWindow.SmallScroll Down:=-6
Range("B4").Select
ActiveSheet.Paste
End Sub


Can someone guide me to what i need to change or provide the correct code?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Welcome to the Board!

When you call other macros, you do NOT use the "Sub" part in your call statement.
It would just be:
Code:
Call MacroName
And if you want a confirmation check, you need to do something like this:
Code:
myCheck = MsgBox([COLOR=#333333]"Are you sure you want to clear the sheet?", vbYesNo)
If myCheck = vbYes Then
'   Call your macro here
End If[/COLOR]
 
Upvote 0
I also wouldn't use native code lines as the name of a macro
Code:
Sub MsgBoxYesNo()
 
Upvote 0
Could you help me with this code?

Like I mentioned...Need the message box to ask yes or no with the are you sure message. and then I need it to be able to be used with my recorded macro...

This is all new to me again...have not done this for many years... any additional help would be great.
 
Upvote 0
None of the code you provided clears cells.
So can you post the code that does this please.
 
Upvote 0
The code I’m using is a record macro function. This is working on the button I have. I need the warning message to be added as well.
 
Upvote 0
This is the record macro I am using..

Sub test()
'
' test Macro
'


'
Sheets("backup").Select
Selection.Copy
Sheets("IPT MEETING SCHEDULE").Select
ActiveSheet.Paste
Range("B4").Select
End Sub
 
Upvote 0
Maybe this, but as mentioned this does NOT delete anything it simply copies data to another sheet ???

Code:
Sub test()
MsgBox "Are you sure you want to clear the sheet?", vbYesNo
If vbYes = True Then
Sheets("backup").Select
Selection.Copy
Sheets("IPT MEETING SCHEDULE").Select
ActiveSheet.Paste
Range("B4").Select
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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