Can i call a macro name from a cell value?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,037
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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

rehanemis

New Member
Joined
Aug 15, 2016
Messages
47
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.
 

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,037
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
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
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
14,761
Office Version
  1. 365
Platform
  1. Windows
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,597
Messages
5,838,265
Members
430,536
Latest member
Manoj Gaidhankar

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