Run a Function

Forestq

Active Member
Joined
May 9, 2010
Messages
482
Hi,

I have function which is formating headers and works OK.

Code:
Function Header()
.....
End Function

In sheet1 I added button.

How to do that:
- if I click on the button function will run and do formating changes?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
There are two types of buttons that can be added to worksheets: ActiveX controls and Form Controls.

Right-click on the button and do the following:

1. If the button is an ActiveX control, you'll see an option "View Code".
Click that and it will open up the VB Editor inside a procedure like this....

Code:
Private Sub CommandButton1_Click()

End Sub

Just insert a call to your function
Code:
Private Sub CommandButton1_Click()
   Call Header
End Sub

2. If the button is a Form Control, you'll see an option "Assign macro...".
Click that and it will open an "Assign Macro" dialog window with a place to enter the macro's name.
There is a list of available macros below, but those are Subs, not Functions.

You can type your function's name in the box and if it is found by Excel it will be linked to that button.

Unless you need to return values from your Procedure, you could make that a Sub instead of a Function.
 
Upvote 0
Thanks Jerry!

Much appreciate your help and explanation, thank you once again!

regards,
Pawel
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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