Can i call a macro name from a cell value?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
HI Everyone,

I have a standard macro i use in lots of places but i find myself making lots of copy's because in it i have the comand "Call" (Another macro) and the macro i want to call can be different .

so i was wondering if i could instead of say "Call" (Another macro) i could list that macros name in sheets "Macros" say "D7" and have it call it instead?

can this be done? if so how?

thanks

Tony
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Why not you make a button to call it every time or just place in the standard module and call it from anywhere in your sheets.
 
Upvote 0
Ok so heres an exaple of the code,

now the thing is i would nornally have to


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("AE1:AH500")) Is Nothing Then
If Range("Z" & Target.Row) = "Dropdown" Then
Call TonyDoesGreen1
Exit Sub
End If
End If

'reapeat code

If Not Intersect(Target, Range("AE1:AH500")) Is Nothing Then
If Range("Z" & Target.Row) = "TextBox" Then
Call TonyDoesRed1
Exit Sub
End If
End If

'and there ight be 25 different calls so i make 25 copies of the code
whereas i could put:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("AE1:AH500")) Is Nothing Then
If Range("Z" & Target.Row) = "Use" Then
Call  Range("Y" & Target.Row) .value  @but this is the row i dont know if it will work?
Exit Sub
End If
End If
 
Upvote 0
Are all of the macros in the same module?

To do what you want, you need to call the macro by workbook name, module and macro name with something similar to
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("AE1:AH500")) Is Nothing Then
    If Range("Z" & Target.Row) = "Use" Then
        Application.Run "'" & ThisWorkbook.Name & "'!VBAProject." & "Module1." & Range("Y" & Target.Row).Value
        Exit Sub
    End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,252
Members
449,075
Latest member
staticfluids

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