ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   multiple if's (https://www.excelbanter.com/excel-programming/396636-multiple-ifs.html)

snax500

multiple if's
 
I have to convert many accounts to a new account string. I have many
Or's. Is there a better way to code this? ( I actually have 16 Or's- I
only show 4 for the example):

For Each cll In Selection
old = Right(cll, 4)
If old = "0101" Or old = "0102" Or old = "0103" Or old = "0104"
Then
CONVERT CLL
End If
Next


Thanks


JW[_2_]

multiple if's
 
Not really a whole lot of information to go on. But, I would most
likely use a Select Case statement
Select Case old
Case "0101"
whatever goes here
Case "0102"
something else goes here
End Select

You can include a Case Else statement at the end of the Case
statements if you need to.
snax500 wrote:
I have to convert many accounts to a new account string. I have many
Or's. Is there a better way to code this? ( I actually have 16 Or's- I
only show 4 for the example):

For Each cll In Selection
old = Right(cll, 4)
If old = "0101" Or old = "0102" Or old = "0103" Or old = "0104"
Then
CONVERT CLL
End If
Next


Thanks



p45cal[_50_]

multiple if's
 
For Each cll In Selection
Select Case Right(cll, 4)
Case "0101","0102" ,"0103", "0104" 'you might get away with Case "0101" to
"0104" here but needs testing
CONVERT CLL
Case 'another list
Case 'yet another list
Do something
Case Else
Only do something here if none of the others above have triggered
End Select
Next


--
p45cal


"snax500" wrote:

I have to convert many accounts to a new account string. I have many
Or's. Is there a better way to code this? ( I actually have 16 Or's- I
only show 4 for the example):

For Each cll In Selection
old = Right(cll, 4)
If old = "0101" Or old = "0102" Or old = "0103" Or old = "0104"
Then
CONVERT CLL
End If
Next


Thanks




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

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