Call sub based on value in cell

ANRoebuck

New Member
Joined
Nov 21, 2018
Messages
5
I'd like to set up a sub to call another sub based on a value in a cell, rather than calling a specific pre-defined sub.

For example:

Code:
Sub test1()
x = Worksheets("Sheet1").Range("B2").Value
Call x
End Sub

Sub test2()
Worksheets("Sheet1").Range("B4").Value = "test2 has run"
End Sub


Sub test3()
Worksheets("Sheet1").Range("B4").Value = "test3 has run"
End Sub

Unfortunately 'call x' doesn't work as I had hoped.

The intention is that, in the above example, when test1 is run, if the value in B2 is "test2", test2 will be called; if the value in B2 is "test3", test 3 will be called.

Does anybody know of a way to make this work?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try:

Code:
Application.Run (Worksheets("Sheet1").Range("B2").Value)
 
Upvote 0
Try Application.Run.
Code:
Sub test1()
    x = Worksheets("Sheet1").Range("B2").Value
    Application.Run x
End Sub

Sub test2()
    Worksheets("Sheet1").Range("B4").Value = "test2 has run"
End Sub

Sub test3()
    Worksheets("Sheet1").Range("B4").Value = "test3 has run"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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