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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,215,032
Messages
6,122,770
Members
449,095
Latest member
m_smith_solihull

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