Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with case statement 2

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
i using a case statement, however one of the "cases" is giving me trouble...im basically assigning a variable a string value, however one of the "cases" i wont necessarily know exactly, i just konw that it will end in "...DA Calls"

i tried using the case statement with wildcharacters, with MOU as my variable like this

select case MOU
case "*DA Calls"
...
end select

however its not reading it the way i want to, its looking for an exact, case-sensitive string,...is there around this, should i use if statements instead...thanks!!!



 
I think it should be something like

select case MOU

Case is like "*" & "DA Calls"

End select

if you don't want this to be case sensitive you need to have set option compare text in your declarations
 
You could Store the string variable using:

StNewString = Right(MOU,8)

Which will store DA Calls in the variable StNewString

Rgds, John

 
No real difference between IFs and Select Case apart from Select case is a bit faster and I prefer the way it looks
However, the downside is that you can't use "Like" so you've got 2 options

1:
If Range("A1").Text Like "*DA Calls" Then

2:
Select case right(MOU,8)
case "DA Calls"
etc etc

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
yea thanks, i just read that u cant use "is" or "like" so actually what i did was as my last "case" i did

case else
if MOU like "*DA calls" then......

however, i would like it to NOT be case-sensitive, so how would i achieve what RivetHed was saying, thanks!!
 
sorry didn't realise you couldn't use like in select case, learn something new every day.
anyway just pop the line: "option compare text" into the declarations sections at the top of the module and that should remove case sensitivity
 
well i just learned something else today too, thanks!!!
 
if UCase(MOU) like "*DA CALLS" then

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
true, true, i was thinking also about making it all either upper or lowercase, good suggestion xlbo!
 
4335,
Here's another way...

strXXX = "abcdef"
Select Case strXXX
Case "XXXXXX"
Case "YYYYYY"
Case "ZZZZZZ"
Case Else
Select Case UCase(strXXX) Like UCase("*CdeF")
Case True
strXXX = "BBB"
Case Else
End Select
End Select

Tranman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top