run a macro from a value in a cell

AndyD

Active Member
Joined
Nov 14, 2002
Messages
449
hi there
I have an index formula in a cell, so for example it could return "macro1" or "macro2".

What vba do i need do runs the macro mentioned in the cell?

Cheers

Andy
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

danial

Board Regular
Joined
Apr 29, 2006
Messages
107
Put below code to your vba page (your sheet which contain there index)
Code:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.SubAddress = "" Then Run (Target.Name)
End Sub

this way work when you set the index to hyperlink
you can use below code to set your index to hyperlink
if you index kept in column "A"
Code:
For K = 1 To [A1].End(xlDown).Row
ActiveSheet.Hyperlinks.Add cells(K,1), "", "", , cells(K,1).Value
Next
 

AndyD

Active Member
Joined
Nov 14, 2002
Messages
449
Hi Thanks for your reply

its actually a little bit different to this...i dont want a macro to automatically run when the value in the cell is changed.

I want users to press a "create report" button that does something first (macro_part_1) then runs the macro in the cell for part 2

Hope makes sense?
Cheers
Andy
 

danial

Board Regular
Joined
Apr 29, 2006
Messages
107
Is this code as you want?
Code:
For K = 1 To [A1].End(xlDown).Row 
Run cells(K,1)
Next
 

Forum statistics

Threads
1,136,517
Messages
5,676,314
Members
419,619
Latest member
jalme

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