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

  • Thread starter Thread starter Darin Kramer
  • Start date Start date
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
 
How about

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

or am I missing something obvious?
 
AWESOME thanks!!! Just did not know VB that well - Call Macro is the
command I wanted!! Thanks!
 
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....
 
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
 
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
 
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
 
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
 
Back
Top