How to run a Macro depending on a result of a cell

D

Darin Kramer

Howdie!

I need to run a macro that, depending on the result in a cell, runs
another Macro (second macro is just a hide of a column)

So for example, when the user runs Macro 1 it needs to check the value
in Cell A1. If A1 = Yes, then run Macro number 2. If the value in a1 =
No, then dont run any Macros and the first macro can be stopped.

Any ideas?

Thanks and Regards

Darin
 
J

Jack Sheet

How about

If Range("A1").Value = "Yes" Then Call Macro2

or am I missing something obvious?
 
D

Darin Kramer

AWESOME thanks!!! Just did not know VB that well - Call Macro is the
command I wanted!! Thanks!
 
D

Darin Kramer

Can I just duplicate that command for the result of a different cell
running another macro....? doesnt seem to work, unless I need to add an
and...or the like....
 
D

Darin Kramer

Hi Frank

Okay complete requirements are...

IF Cell value a1 = 1 then run macro 1 AND
IF Cell value a1 = 0 then run macro 2 AND
If cell value a2 = 0 then run macro 3 AND
if Cell value a2 = 1 then run macro 4 AND
if cell value a3 = 0 then run macro 5 AND
if cell value a3 = 1 then run macro 6

Ie when user runs the inital macro - macro must check all of the above
cells, and then depending upon the value on the cell run another Macro
or not.

Thanks!!!

Darin
 
F

Frank Kabel

Hi
one way:

with activesheet.range("A1")
if .value=1 then
macro1
elseif .value=0 then
macro2
elseif .offset(1,0).value=0 then
macro3
elseif .offset(1,0).value=1 then
macro4
elseif .offset(2,0).value=0 then
macro5
elseif .offset(2,0).value=1 then
macro6
end if
 
D

Darin Kramer

Hi.........

Almost there.... it just doesnt work if both conditions are true - so
say a1 = 1 - it runs the macro fine, AND a2 = 0, it does not run Macro
2.

Does the else if command continue running if the first condition is
true, ie does not stop immediately?

(I had to modify the syntax and add end if, and end with....

I appreciate your effort Frank
 
F

Frank Kabel

Hi
no, the Elseif command is only executed if the previous condition(s)
are evaluated to False. So in your case you have to use multiple If
then Endif statements
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top