Macro and If Statement

  • Thread starter Thread starter SATB
  • Start date Start date
S

SATB

Here's the situation: I have a worksheet that will have an "X" in
either cell F3 or G3 or H3. What I would like to do (via a macro), is
to examine F3, G3 and H3, and if there is an "X" in anyone of those
cells, to run another specific macro.

For example:

Run a macro (for example called "totalsummary")to determine...

If there is an "X" in F3, then run a macro called "summaryEL";
If there is an "X" in G3, then run a macro called "summaryHT";
If there is an "X" in H3, then run a macro called "summaryFA".

This has to be a macro that starts this process, rather than an if
statement, as I wish to control when this process will happen seperate
from the condition.

In other words, the macro that I run will have if statements imbedded,
and if anyone one of those if statements are true (as it will be only
one), the result is antoher seperate macro running.

Is this a long way of doing this, or is there a better way.

Thanks in advance.

Pete
 
Hi
one way:

'....
with activesheet.range("F3")
if .value="X" then
summaryEL
elseif .offset(0,1).value)="X" then
summaryHT
elseif .offset(0,2).value)="X" then
summaryFA
end if
end with
'...
 
Frank: Thanks very much for your suggestion...however there was a
slight error when it went to the "elseif.offset(0,1).value..."
statement. I modified the macro as follows, and it worked great...

Sub summary()
'
With ActiveSheet.Range("F3")
If .Value = "X" Then
summaryEL
ElseIf ActiveSheet.Range("G3") = "X" Then
summaryHT
ElseIf ActiveSheet.Range("H3") = "X" Then
summaryFA
End If
End With
End Sub

Again, thanks for your help.
Pete
 

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

Back
Top