How can I run my macro within a function

exceere

New Member
Joined
Jul 18, 2012
Messages
26
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"
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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.
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

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