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?
 
I will try...

Yes I do not want to delete all...I am actually only clearing the conditional formatting on the schedule...Sorry I did not mention that...Its a 2 week work schedule with formatting
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Is there a way to send this to you in this thread? so you can check it? I still can't get it to work. it will clear the format in the record macro..I can't seem to get the message to come up.
 
Upvote 0
How many macros are you using....Post ALL of your code if more than one macro
 
Upvote 0
It is just the macro recording that I shared. And I was trying to add the message for the button Yes/No to that
 
Upvote 0
I have tried both to put on top and bottom of the record macro..it does the clear formating fine...I don't get the popup for the message i want




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


Sub top()
'
' top Macro
'


'
Sheets("backup").Select
Selection.Copy
Sheets("IPT MEETING SCHEDULE").Select
ActiveSheet.Paste
End Sub
 
Upvote 0
Try...on the button click

Code:
Sub Button1_Click()
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
Try...on the button click

Code:
Sub Button1_Click()
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



Didn't work... Cannot run macro...the macro may not be available in the workbook or macros are disabled.

The issue is that I need to configure the record macro first? and then edit the code on the button to add the message?

so there is 2 lines in it?
 
Upvote 0
Didn't work... Cannot run macro...the macro may not be available in the workbook or macros are disabled.
Did you check to see if you have enabled macros?
 
Upvote 0
I’m at home.. yes they are.. because the one is working for the clear format. Sorry I live in Japan.. it’s 10:30 at night.. I will check tomorrow.. any other advice or things to check.. I really appreciate it!
 
Upvote 0
I find that when something is not working, it is often best to come at it from a different angle.

In this case here, I would recommend re-stating the problem in a different way. Instead of providing the code, simply explain to us (in plain English) EXACTLY everything you want your code to do (be sure to include sheet names, cell references, etc). And we can see if we can write code to do that (forgetting what you already did/tried). So really, starting from scratch based on the requirements.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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