ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   run a macro from a cell reference (https://www.excelbanter.com/excel-programming/284919-run-macro-cell-reference.html)

spence[_3_]

run a macro from a cell reference
 
if i have the name of a macro in cell A1, how can i run
it by referencing the cell address? supposing the value
of A1 will change.
like if i clicked a CommandButton and cell A1
said "PrintSheetOne" it would run the macro
PrintSheetOne. and likewise for two and three etc. i
have :
Private Sub CommandButton4_Click()
Run "(Sheets(Report).Range(A1))"

End Sub
where have i gone wrong?

TIA

Chip Pearson

run a macro from a cell reference
 
Spence,

Try something like

Application.Run Worksheets("Sheet1").Range("A1").Text



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"spence" wrote in message
...
if i have the name of a macro in cell A1, how can i run
it by referencing the cell address? supposing the value
of A1 will change.
like if i clicked a CommandButton and cell A1
said "PrintSheetOne" it would run the macro
PrintSheetOne. and likewise for two and three etc. i
have :
Private Sub CommandButton4_Click()
Run "(Sheets(Report).Range(A1))"

End Sub
where have i gone wrong?

TIA




Martin[_13_]

run a macro from a cell reference
 
hello, try to rephrase like this
Sub CallHello(
Dim MacroToRun As Varian

MacroToRun = ThisWorkbook.Sheets("Sheet1").Range("A1"
Run MacroToRu

End Su

Sub Hello(
MsgBox "Hello
End Su

regard
Martin


All times are GMT +1. The time now is 02:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com