LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Using LIKE in case statement

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

 
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
Case Statement jlclyde Excel Discussion (Misc queries) 3 December 4th 08 05:04 PM
Anyone actually get Case statement to work ... ? ForestFeeder Excel Worksheet Functions 3 April 21st 06 04:14 PM
Case Of Statement hfazal Excel Programming 2 February 14th 06 08:18 PM
Case Statement Help stck2mlon Excel Programming 3 June 2nd 04 01:44 PM
Case statement smi Excel Programming 2 October 18th 03 02:20 PM


All times are GMT +1. The time now is 03:08 AM.

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

About Us

"It's about Microsoft Excel"