Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DG DG is offline
external usenet poster
 
Posts: 46
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 915
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
DG DG is offline
external usenet poster
 
Posts: 46
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using LIKE in case statement Greg Snidow Excel Programming 7 February 19th 10 01:16 AM
If Statement with Wildcards not Working cr0375 Excel Worksheet Functions 7 September 4th 09 12:59 AM
Wildcards in IF statement Ant Excel Discussion (Misc queries) 5 May 26th 09 09:15 PM
VBA Case statement Ken[_4_] Excel Programming 4 January 26th 09 10:07 PM
Case Statement jlclyde Excel Discussion (Misc queries) 3 December 4th 08 05:04 PM


All times are GMT +1. The time now is 05:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"