run macros from a list of names in a work sheet one at a time by using the same pressing shift and letter

Ratigan1970

New Member
Joined
Jan 22, 2024
Messages
7
Office Version
  1. 2010
Platform
  1. Windows
hi everyone at MrExcel
im totally stuck on this problem and not sure if its possable
im trying to run 8 macros one at a time, so when i press a the same hot key it will play the first macro name in a list in a worksheet. the list is all the names of the macros to play in order.
so when A1 runs and finishes, the next time i press the same hot key the macro name will run in A2 and so on but when it runs the 8th macro and finishes it will return too the macro name in cell A1

fingers crossed that someone can help please
if you need more info just ask thank you all
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You cannot assign different Macros to the same Hotkey. However, you can assign a Macro to a Hotkey that then calls the other Macros. You could also put a Static counter in a Macro that counts the number of times you've hit a Hotkey and runs the appropriate Macro.
 
Upvote 0
Here's an example of using a Static counter. Under Developer tab; select Macros, select the Macro (RunMacro), click options, assign Hotkey. Test.
VBA Code:
Option Explicit

Public cntr As Integer

Sub RunMacro()
Select Case cntr
    Case Is = 0
        MsgBox "Macro1" 'Enter Call to first Sub here
        cntr = cntr + 1
    Case Is = 1
        MsgBox "Macro2" 'Enter Call to second Sub here
        cntr = cntr + 1
    Case Is = 2
        MsgBox "Macro3" 'Enter Call to third Sub here 
        cntr = 0
End Select
End Sub
 
Upvote 0
Solution
If the macros might not all be run during the same excel session (eg the first one might be run today and the second one not for a few days) then maybe something like this.
Set up the macro list something like this (my test just has 3 macros)

Ratigan1970.xlsm
AB
1Macro nameRun?
2Macro1
3Macro2
4Macro3
5
MacroList


Then in Module1 I have this

VBA Code:
Sub Run_Next_Macro()
  Dim m As Long, r As Long
  
  With Sheets("MacroList")
    m = .Columns("A").SpecialCells(xlConstants).Count - 1
    r = .Columns("B").SpecialCells(xlConstants).Count
    If r > m Then
      .Range("B2").Resize(r - 1).ClearContents
      r = 1
    End If
    .Range("B" & r + 1).Value = "Y"
    Application.Run "'" & ThisWorkbook.Name & "'!VBAProject.Module1." & Sheets("MacroList").Range("A" & r + 1).Value
  
  End With
End Sub

Sub Macro1()
  MsgBox "Macro1 has run"
End Sub

Sub Macro2()
  MsgBox "Macro2 has run"
End Sub

Sub Macro3()
  MsgBox "Macro3 has run"
End Sub

The hot key runs the macro Run_Next_Macro
 
Upvote 0
thank you both for your quick reply's, both work for what i need to do
ive been pulling my hair out for weeks trying to work it out

Ive gone for Skyybots reply because its so simply to modify for other projects.

thank you both for your time
 
Upvote 0
both work for what i need to do
.. but not what your thread title and post 1 description asked for. ;)
run macros from a list of names in a work sheet one at a time
when i press a the same hot key it will play the first macro name in a list in a worksheet.

Also, just confirming that if you want to use this again at a later time you want to start at the first macro again rather than continuing on from where you left off last time?
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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