ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If Then else (https://www.excelbanter.com/excel-programming/405690-if-then-else.html)

Eric

If Then else
 
HELP!! I am trying to figure out an if then else statement. I have it
working for two conditions but I need to make it for 3 conditions.

Cell: sheet "A" C1=1


sub if_then_else

If C1=1 then macro "A"

sheets("A").select

If C1=2 then macro "B"

sheets("B").select

else "C"

sheets("C").select

end if
end sub

I know the above isn't correct but I am trying to give you an idea of what I
need,
I am trying to make this work in VBA. (Macro "A", "B", "C", are all in the
formula I just didn't type the whole thing out.

If any one can Help I would appreciate it. Thanks

Eric

Don Guillett

If Then else
 
this or a selectcase

sub if_then_else'select variable sheet
If range("c1")=1 then sheets("A").select
If range("c1")=2 then sheets("b").select
if range("c1")=3then sheets("c").select
end sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Eric" wrote in message
...
HELP!! I am trying to figure out an if then else statement. I have it
working for two conditions but I need to make it for 3 conditions.

Cell: sheet "A" C1=1


sub if_then_else

If C1=1 then macro "A"

sheets("A").select

If C1=2 then macro "B"

sheets("B").select

else "C"

sheets("C").select

end if
end sub

I know the above isn't correct but I am trying to give you an idea of what
I
need,
I am trying to make this work in VBA. (Macro "A", "B", "C", are all in
the
formula I just didn't type the whole thing out.

If any one can Help I would appreciate it. Thanks

Eric



Mike

If Then else
 
Another way is Select Case
Sub whichMacroToRun()

Select Case Range("C1").Value
Case 1
MsgBox "Macro1"
Case 2
MsgBox "Macro2"
Case Else
MsgBox "MacroElse"
End Select
End Sub

"Eric" wrote:

HELP!! I am trying to figure out an if then else statement. I have it
working for two conditions but I need to make it for 3 conditions.

Cell: sheet "A" C1=1


sub if_then_else

If C1=1 then macro "A"

sheets("A").select

If C1=2 then macro "B"

sheets("B").select

else "C"

sheets("C").select

end if
end sub

I know the above isn't correct but I am trying to give you an idea of what I
need,
I am trying to make this work in VBA. (Macro "A", "B", "C", are all in the
formula I just didn't type the whole thing out.

If any one can Help I would appreciate it. Thanks

Eric


Don Guillett

If Then else
 

or
Select Case Range("C1").Value
Case 1:s="a"
Case 2:s="b"
case3:s="c"
Case Else
End Select
sheets(s).select
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mike" wrote in message
...
Another way is Select Case
Sub whichMacroToRun()

Select Case Range("C1").Value
Case 1
MsgBox "Macro1"
Case 2
MsgBox "Macro2"
Case Else
MsgBox "MacroElse"
End Select
End Sub

"Eric" wrote:

HELP!! I am trying to figure out an if then else statement. I have it
working for two conditions but I need to make it for 3 conditions.

Cell: sheet "A" C1=1


sub if_then_else

If C1=1 then macro "A"

sheets("A").select

If C1=2 then macro "B"

sheets("B").select

else "C"

sheets("C").select

end if
end sub

I know the above isn't correct but I am trying to give you an idea of
what I
need,
I am trying to make this work in VBA. (Macro "A", "B", "C", are all in
the
formula I just didn't type the whole thing out.

If any one can Help I would appreciate it. Thanks

Eric



Eric

If Then else
 
Thank you Don,

When I do the select Case Range ("C1").value ~~~ should I put the value
that I am looking for? So, what would it look like if the value can be
between 1 and 3?
Would it look like this?

Select Case Range ("C1").Value
Case 1: C1=1
run this macro

Case 2: C1=2
run this macro

Case 3: C1=3
run this macro

Case Else
End Select
Sheets("whatever sheet I want").select

End Sub

Is this what it would look like?

Eric
"Don Guillett" wrote:


or
Select Case Range("C1").Value
Case 1:s="a"
Case 2:s="b"
case3:s="c"
Case Else
End Select
sheets(s).select
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mike" wrote in message
...
Another way is Select Case
Sub whichMacroToRun()

Select Case Range("C1").Value
Case 1
MsgBox "Macro1"
Case 2
MsgBox "Macro2"
Case Else
MsgBox "MacroElse"
End Select
End Sub

"Eric" wrote:

HELP!! I am trying to figure out an if then else statement. I have it
working for two conditions but I need to make it for 3 conditions.

Cell: sheet "A" C1=1


sub if_then_else

If C1=1 then macro "A"

sheets("A").select

If C1=2 then macro "B"

sheets("B").select

else "C"

sheets("C").select

end if
end sub

I know the above isn't correct but I am trying to give you an idea of
what I
need,
I am trying to make this work in VBA. (Macro "A", "B", "C", are all in
the
formula I just didn't type the whole thing out.

If any one can Help I would appreciate it. Thanks

Eric




Don Guillett

If Then else
 
My understanding is that you wanted to put 1,2 or 3 in cell c1 and select
sheet a,b, or c.? I gave you a macro to do that. What do you want??
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Eric" wrote in message
...
Thank you Don,

When I do the select Case Range ("C1").value ~~~ should I put the value
that I am looking for? So, what would it look like if the value can be
between 1 and 3?
Would it look like this?

Select Case Range ("C1").Value
Case 1: C1=1
run this macro

Case 2: C1=2
run this macro

Case 3: C1=3
run this macro

Case Else
End Select
Sheets("whatever sheet I want").select

End Sub

Is this what it would look like?

Eric
"Don Guillett" wrote:


or
Select Case Range("C1").Value
Case 1:s="a"
Case 2:s="b"
case3:s="c"
Case Else
End Select
sheets(s).select
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mike" wrote in message
...
Another way is Select Case
Sub whichMacroToRun()

Select Case Range("C1").Value
Case 1
MsgBox "Macro1"
Case 2
MsgBox "Macro2"
Case Else
MsgBox "MacroElse"
End Select
End Sub

"Eric" wrote:

HELP!! I am trying to figure out an if then else statement. I have
it
working for two conditions but I need to make it for 3 conditions.

Cell: sheet "A" C1=1


sub if_then_else

If C1=1 then macro "A"

sheets("A").select

If C1=2 then macro "B"

sheets("B").select

else "C"

sheets("C").select

end if
end sub

I know the above isn't correct but I am trying to give you an idea of
what I
need,
I am trying to make this work in VBA. (Macro "A", "B", "C", are all
in
the
formula I just didn't type the whole thing out.

If any one can Help I would appreciate it. Thanks

Eric






All times are GMT +1. The time now is 12:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com