Need help with cell-value-dependent macros

Nivram3330

New Member
Joined
Dec 11, 2016
Messages
2
Hi folks. I love Excel but I know just enough to be dangerous, or to get myself stuck, and I know basically nothing about VB. I have a single worksheet on which I have 9 macros that I recorded. I also have a command button which, when clicked, is supposed to run one of the macros. It is this that complicates things beyond my ability. Whether each macro runs is supposed to be dependent on there being a Y in the cell I want the macro to evaluate. My macro names and the cells which need to be evaluated are as follows:

Macro Name Cell to Evaluate
Jan22................AH29
Mar5.................AI29
Apr16................AJ29
May28...............AK29
Jul9..................AL29
Aug20...............AM29
Oct1.................AH30
Nov12...............AI30
Dec24...............AJ30

Only one of the above cells will ever have a Y in it at any one time. I would like the script to have the macro run through the cells and, when it finds the one with the Y, run that macro, but obviously skip the others. I tried the following to see if I was on the right track, but this runs the macro regardless of the contents of cell AH29. I'm sure it's ridiculously wrong but, as I said, I know nothing about VB.


Private Sub CommandButton1_Click()

If AH29 = Y Then
Application.Run "Jan22"
End If

End Sub


I know I'm a noob, but I sure would appreciate any help.

Thanx Everyone

Nivram3330
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Welcome to the board.

Code:
If Range("AH29").Value = "Y" Then
 
Last edited:
Upvote 0
Try something like this (note: not tested):
Code:
Private Sub CommandButton1_Click()
    cAddr = Array("AH29", "AI29", "AJ29", "AK29", "AL29", "AM29", "AH30", "AI30", "AJ30")
    mName = Array("Jan22", "Mar5", "Apr16", "May28", "Jul9", "Aug20", "Oct1", "Nov12", "Dec24")
    For i = LBound(cAddr) To UBound(cAddr) Step 1
        If Range(cAddr(i)).Value = "Y" Then Application.Run mName(i): Exit Sub
    Next i
End Sub
 
Upvote 0
Tetra201,

Thank you so much!! This worked perfectly the very first time. Sure is nice to have help from a community with such considerate members.
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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