Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wildcards in a case statement
I have a column that contains a 2 character code. How can I use only one
case statement to be true for all cases where the cell started with a C? For example the cell could contain CA, CD, CQ, C5 etc. Select Case Cells(x,9) Case "BQ" Rejected = False Case "C*" Rejected = True End Select Dan |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wildcards in a case statement
DG wrote:
I have a column that contains a 2 character code. How can I use only one case statement to be true for all cases where the cell started with a C? For example the cell could contain CA, CD, CQ, C5 etc. Select Case Cells(x,9) Case "BQ" Rejected = False Case "C*" Rejected = True End Select Dan You can do it like this: Select Case Cells(x,9) Case "BQ" Rejected = False Case Else If Cells(x,9) Like "C*" Then Rejected = True End If End Select Of course, if you are only testing two conditions you don't really need Select Case. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wildcards in a case statement
In theory you could do something like this
Select case True Case Left$(Cells(x, 9), 1) = "C" ' other Case's must evaluate to a boolean However for your two conditions simply use If...ElseIf s = Ucase(Cells(x,9)) ' assuming case insensitive If s = "BQ" then Elseif Left$(s,1) + "C" then ElseIf blah then End If Regards, Peter T "DG" wrote in message ... I have a column that contains a 2 character code. How can I use only one case statement to be true for all cases where the cell started with a C? For example the cell could contain CA, CD, CQ, C5 etc. Select Case Cells(x,9) Case "BQ" Rejected = False Case "C*" Rejected = True End Select Dan |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wildcards in a case statement
typo!!
Elseif Left$(s,1) + "C" then should of course read Elseif Left$(s,1) = "C" then Peter T "Peter T" <peter_t@discussions wrote in message ... In theory you could do something like this Select case True Case Left$(Cells(x, 9), 1) = "C" ' other Case's must evaluate to a boolean However for your two conditions simply use If...ElseIf s = Ucase(Cells(x,9)) ' assuming case insensitive If s = "BQ" then Elseif Left$(s,1) + "C" then ElseIf blah then End If Regards, Peter T "DG" wrote in message ... I have a column that contains a 2 character code. How can I use only one case statement to be true for all cases where the cell started with a C? For example the cell could contain CA, CD, CQ, C5 etc. Select Case Cells(x,9) Case "BQ" Rejected = False Case "C*" Rejected = True End Select Dan |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wildcards in a case statement
try this. change activecell to cells(x,9)
Sub iflefttext() If UCase(Left(ActiveCell, 1)) = "C" Then rejected = True ElseIf UCase(ActiveCell) = "BQ" Then rejected = False End If MsgBox rejected End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "DG" wrote in message ... I have a column that contains a 2 character code. How can I use only one case statement to be true for all cases where the cell started with a C? For example the cell could contain CA, CD, CQ, C5 etc. Select Case Cells(x,9) Case "BQ" Rejected = False Case "C*" Rejected = True End Select Dan |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wildcards in a case statement
I'm nost sure what etc means here, but you may want to be explicit:
Dim x As Long Dim Rejected As Boolean x = 1 With ActiveSheet Select Case UCase(.Cells(x, 9).Value) 'always use upper case here! Case "BQ" Rejected = False Case "CA", "CD", "CQ", "C0" To "C5" Rejected = True End Select End With DG wrote: I have a column that contains a 2 character code. How can I use only one case statement to be true for all cases where the cell started with a C? For example the cell could contain CA, CD, CQ, C5 etc. Select Case Cells(x,9) Case "BQ" Rejected = False Case "C*" Rejected = True End Select Dan -- Dave Peterson |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wildcards in a case statement
Thanks, I knew I could find it here.
"DG" wrote in message ... I have a column that contains a 2 character code. How can I use only one case statement to be true for all cases where the cell started with a C? For example the cell could contain CA, CD, CQ, C5 etc. Select Case Cells(x,9) Case "BQ" Rejected = False Case "C*" Rejected = True End Select Dan |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Using LIKE in case statement | Excel Programming | |||
If Statement with Wildcards not Working | Excel Worksheet Functions | |||
Wildcards in IF statement | Excel Discussion (Misc queries) | |||
VBA Case statement | Excel Programming | |||
Case Statement | Excel Discussion (Misc queries) |