Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call Sub based on a variable

Status
Not open for further replies.

DummyForAccess

Technical User
Aug 7, 2002
38
0
0
US
Help, Here's the code I have so far. The error I'm getting is that it's expecting a sub or function. How can I call a sub based on the value contained in cell O2?

Sub M_Run_Macro_D2()


Dim mcro_nm As String
Dim windw As String


Sheets("Macro List").Select
windw = Range("N2").Value

Sheets("Macro List").Select
windw = Range("O2").Value
mcro_nm = Range("O2").Value

Windows(windw).Activate

Call mcro_nm
Windows("MonthendMacros.xls").Activate
Sheets("Day One").Select

End Sub
 
Hi DummyForAccess,

The exact string you need may depend on where your code is, but the statement you need is Application.Run:

Code:
[blue]Application.Run ThisWorkbook.Name & "!" & Range("O2")[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top