Macro Buttons

singingsister

Board Regular
Joined
Jun 13, 2006
Messages
145
I have a long document for which I have set up macros to automatically hide certain columns, as different people will want to view different information in the spreadsheet. I have successfully created the macros and watched it work, but I now want to add buttons to the top of the spreadsheet so all you have to do is click the relevant button for the information you wish to see and the macro is carried out.

HOW do I do this?
:eek:
 
Re: onAction macro with a passed variable??

Any chance someone can talk me through how to do that?

Set MyButton = Activesheet.Buttons.Add (20,30,40,50)

'the numbers in the parenthesis are top, left, height & width

MyButton.Onaction = "RunThisCodeWhenClicked"

Sub RunThisCodeWhenClicked()

'your macro code here

End Sub

take care...

What if the Sub needs to pass a variable:
MyButton.OnAction = "RunThisCodeWhenClicked(ActiveSheet.Index)"

Sub RunThisCodeWhenClicked(SheetIndex as Integer)
' code is here
End Sub

I get 'variable undefined' errors when I try and do that, and if i remove the quotes it expects a function. if i add a sub "Call", more errors.
If it's not possible with OnAction, is there any other type of event handler to do this?

nevermind. figured it out.
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,214,429
Messages
6,119,435
Members
448,898
Latest member
dukenia71

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