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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

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