How can I run my macro within a function

exceere

New Member
Joined
Jul 18, 2012
Messages
24
Hi.

I typed the following code

Code:
Function RunMacro(FunctionName As String)
Application.Run FunctionName
RunMacro = ""
End Function

Sub noclr()
MsgBox "Nothing to clear"
End Sub

Sub clrows()
Sheets("Sheet1").Range("B:B").ClearContents
End Sub
When i type: = RunMacro("noclr"), it excute macro "noclr" and shows the MsgBox

But when i type: = RunMacro("clrows"), it do nothing, and the coulom "D" not cleared

How can I adjust the code so that execeute macro "clrows"
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Hi

Your post is not clear.

Are you trying to execute the function using it in a formula in a cell?

If that's the case it won't work. Functions that are to be used in formulas in cells (called UDF's), like the excel built-in functions, can only be used to calculate a value that is used to determine the value of the cell where they are used.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,530
Messages
5,602,192
Members
414,513
Latest member
junbuggle

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
Top