Using LIKE in case statement
this seemed to work, don't know how kosher it is:
Sub test()
Dim CellB2 As Variant
Dim Prime As Variant
Dim i As Long
CellB2 = Range("B2").Value
Select Case i 0
Case i = InStr(1, CellB2, "Jnet")
Prime = "JNET"
Case i = InStr(1, CellB2, "Mastec")
Prime = "Mastec"
Case i = InStr(1, CellB2, "Ivy")
Prime = "Ivy"
Case i = InStr(1, CellB2, "S&N")
Prime = "S&N"
Case i = InStr(1, CellB2, "Danella")
Prime = "Danella"
End Select
Range("B2").Activate
ActiveCell.Value = Prime
End Sub
--
Gary
"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
|