View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jim Rech Jim Rech is offline
external usenet poster
 
Posts: 2,718
Default Using LIKE in case statement

This is one way to go:

CellB2 = Range("B2").Value
Select Case True
Case CellB2 Like "*Jnet*"
Prime = "JNET"

Also...

Dim CellB2 As Variant
Dim Prime As Variant
CellB2 = Range("B2").Value
Select Case True
Case InStr(1, CellB2, "Jnet") 0
Prime = "JNET"
--
Jim
"Greg Snidow" wrote in message
...
| Greetings all. I am trying be able to use something akin to LIKE in a
case
| statement. I need to set the value of a variable, "Prime" depending on
| whether cell B2 contains certain values, and I have tried the below, to no
| avail.
|
| Dim CellB2 As Variant
| Dim Prime As Variant
| CellB2 = Range("B2").Value
| Select Case CellB2
| Case InStr(1, CellB2, "Jnet")
| Prime = "JNET"
| Case InStr(1, CellB2, "Mastec")
| Prime = "Mastec"
| Case InStr(1, CellB2, "Ivy")
| Prime = "Ivy"
| Case InStr(1, CellB2, "S&N")
| Prime = "S&N"
| Case InStr(1, CellB2, "Danella")
| Prime = "Danella"
| End Select
| Range("B2").Activate
| ActiveCell.Value = Prime
|
| Basically, if this were SQL, it would be
|
| SELECT CASE WHEN CellB2 LIKE 'Jnet' THEN 'Jnet'
| WHEN .....
| END
|
| When I run the macro, cell B2 ends up being blank, so either I am not
| correctly creating the variable CellB2, or there is something wrong with
the
| CASE. Any ideas. Thank you.
|
| Greg
|