MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Excel Macro

Posted by Larry Shuler on February 24, 2001 1:17 PM

Help! I am the novice of all novices. I need to test the value of a cell using a macro, and, run one of two other macros depending on the outcome of the test. Simple thing, but I can't figgure it out.

Posted by David Hawley on February 24, 2001 3:39 PM

Larry, What you need is probably a Select Case statement. Very similar to an IF statement, but a bit neater and more flexible.

Sub TryThis()
Select Case Range("A1").Value
Case 1
Run "Macro1"
Case 2
Run "Macro2"
Case 3 To 6
Run "Macro3456"
Case Is > 7
Run "MacroGreaterThan7"
Case Else
MsgBox "No such macro", vbCritical
End Select
End Sub


OzGrid Business Applications

Posted by Larry Shuler on February 24, 2001 5:12 PM

Thanks, Dave. That worked for me and now I know a little more about what I am doing. Someday, I hope to learn more of this stuff. Thanks again...