ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   when IF equals multiple values?? (https://www.excelbanter.com/excel-programming/278417-when-if-equals-multiple-values.html)

foamfollower

when IF equals multiple values??
 
Hello,
This should be easy, although for some reason........
anyway, i'm trying to say this:
IF 1or3or5or8or10or12or13or15or17or20 then 1, if not then 2.

i understand the basic true or false formula, =if(a1=1,1,2), but how
do i string the commands to assign a '1' to any of the ten above
mentioned numbers. of course, i'd like the other
numbers:2,4,6,7,9,11,14,16,18,19 to be '2'.

Any help will be greatly appreciated.

Have a Great Day!

SF

Jose Rojas

when IF equals multiple values??
 
Sub SF()
Dim i As Long
Select Case Sheets("Sheet1").Range("A1")
Case Is = 1
i = 1
Case Is 1
i = 2
End Select

'Hope It Works!!!

End Sub

"foamfollower" wrote in message
om...
Hello,
This should be easy, although for some reason........
anyway, i'm trying to say this:
IF 1or3or5or8or10or12or13or15or17or20 then 1, if not then 2.

i understand the basic true or false formula, =if(a1=1,1,2), but how
do i string the commands to assign a '1' to any of the ten above
mentioned numbers. of course, i'd like the other
numbers:2,4,6,7,9,11,14,16,18,19 to be '2'.

Any help will be greatly appreciated.

Have a Great Day!

SF




Alan Beban[_3_]

when IF equals multiple values??
 
=IF(OR(A1=1,A1=3,A1=5,A1=8,A1=10,A1=12,A1=13,A1=15 ,A1=17,A1=20),1,2)

Alan Beban

foamfollower wrote:
Hello,
This should be easy, although for some reason........
anyway, i'm trying to say this:
IF 1or3or5or8or10or12or13or15or17or20 then 1, if not then 2.

i understand the basic true or false formula, =if(a1=1,1,2), but how
do i string the commands to assign a '1' to any of the ten above
mentioned numbers. of course, i'd like the other
numbers:2,4,6,7,9,11,14,16,18,19 to be '2'.

Any help will be greatly appreciated.

Have a Great Day!

SF



Bob Kilmer

when IF equals multiple values??
 
"foamfollower" wrote in message
om...
anyway, i'm trying to say this:
IF 1or3or5or8or10or12or13or15or17or20 then 1, if not then 2.
i understand the basic true or false formula, =if(a1=1,1,2), but how
do i string the commands to assign a '1' to any of the ten above


formula (there may be better ones):

=IF( ISNA(MATCH(A1,{1,3,5,8,10,12,13,15,17,20},0)),2,1)


programmatically:

If InStr("01?03?05?08?10?12?13?15?17?20", Format(Range("A1").Text, "00"))
0 Then

x = 1
Else
x = 2
End If

--
Bob Kilmer



Bob Kilmer

when IF equals multiple values??
 
"Jose Rojas" wrote in message
...
Sub SF()
Dim i As Long
Select Case Sheets("Sheet1").Range("A1")
Case Is = 1
i = 1
Case Is 1
i = 2
End Select

'Hope It Works!!!

End Sub


Did you mean something like this?

Sub SF()
Dim i As Long
Select Case Sheets("Sheet1").Range("A1")
Case Is = 1, 3, 5, 8, 10, 12, 13, 15, 17, 20
i = 1
Case Else
i = 2
End Select

End Sub


--
Bob Kilmer





All times are GMT +1. The time now is 05:41 AM.

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