VBA loop that runs a different macro based on cell value

Nickw2619

New Member
Joined
Jul 26, 2017
Messages
2
Hi,

Ive been having a lot of trouble googling this, so thanks in advance for any help you can give. Basically I have a table of data with a number(1-10) in the column at the end (G) I have 10 macros that I want to run based on the number in G. So if the numbers 2 run Macro2 if it's 7 run Macro7. At the end of all the macros the top row gets deleted so what I would like to do is make a until A2 is empty loop that runs the macro corresponding to the value in G2. If anyone can help I'd greatly appreiate it and if I need to explain more let me know.

Thanks!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Nick,

Give this code a try:

Code:
Option Explicit
Sub InitiateMacros()
Dim currval As Integer
Dim i As Long


Do Until Cells(2, 1) = ""
    currval = Cells(1, 7).Value
    Select Case currval
        Case 1
            Call Macro1
        Case 2
            Call Macro2
        Case 3
            Call Macro3
        Case 4
            Call Macro4
        Case 5
            Call Macro5
        Case 6
            Call Macro6
        Case 7
            Call Macro7
        Case 8
            Call Macro8
        Case 9
            Call Macro9
        Case 10
            Call Macro10
    End Select
    i = i + 1
Loop


End Sub
 
Upvote 0
Frank,

Did it without the loop just to test it and make sure it works and it was working flawlessly. I'm curious what the Option Explicit before the Sub means and what it's for.

Thanks
 
Upvote 0
Option Explicit means that you must declare all/any variables you use in your code module. If you monitor this Forum you will see that reiterated by all of the experts that have posted thousands of times here. It insures you know what variables you are using and what type of variable it is set to be. Always better to declare a variable as a specific type as opposed to Variant which uses more memory.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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