Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default Combining multiple like's with Or?

I'm trying to categorize certain products into one of three segments based on
their name. Since I have about 100 products, I'd rather not write a "like"
statement for each and every product. Is there a way to combine them so I
can do something like the following?

If Range("H2").Offset(i, 0).Value Like "*prod1*" Or "*prod2*" Then
Range("W2").Offset(i, 0).Value = "Segment1"

Currently I get a type mismatch error on the first of the lines shown here.
Any suggestions?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Combining multiple like's with Or?

Rather than this:
If Range("H2").Offset(i, 0).Value Like "*prod1*" Or "*prod2*" ...

YOu need this:
If Range("H2").Offset(i, 0).Value Like "*prod1*" Or Like "*prod2*"

"StumpedAgain" wrote:

I'm trying to categorize certain products into one of three segments based on
their name. Since I have about 100 products, I'd rather not write a "like"
statement for each and every product. Is there a way to combine them so I
can do something like the following?

If Range("H2").Offset(i, 0).Value Like "*prod1*" Or "*prod2*" Then
Range("W2").Offset(i, 0).Value = "Segment1"

Currently I get a type mismatch error on the first of the lines shown here.
Any suggestions?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Combining multiple like's with Or?

If Range("H2").Offset(i, 0).Value Like "*prod1*" _
Or Range("H2").Offset(i, 0).Value Like "*prod2*" Then

or maybe...

If lcase(Range("H2").Offset(i, 0).Value) Like "*prod1*" _
Or lcase(Range("H2").Offset(i, 0).Value) Like "*prod2*" Then


StumpedAgain wrote:

I'm trying to categorize certain products into one of three segments based on
their name. Since I have about 100 products, I'd rather not write a "like"
statement for each and every product. Is there a way to combine them so I
can do something like the following?

If Range("H2").Offset(i, 0).Value Like "*prod1*" Or "*prod2*" Then
Range("W2").Offset(i, 0).Value = "Segment1"

Currently I get a type mismatch error on the first of the lines shown here.
Any suggestions?


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default Combining multiple like's with Or?

I tried this but I still get the mismatch error. I think when I use the "Or"
it wants to match numerical values? Any other thoughts/suggestions?

"Sam Wilson" wrote:

Rather than this:
If Range("H2").Offset(i, 0).Value Like "*prod1*" Or "*prod2*" ...

YOu need this:
If Range("H2").Offset(i, 0).Value Like "*prod1*" Or Like "*prod2*"

"StumpedAgain" wrote:

I'm trying to categorize certain products into one of three segments based on
their name. Since I have about 100 products, I'd rather not write a "like"
statement for each and every product. Is there a way to combine them so I
can do something like the following?

If Range("H2").Offset(i, 0).Value Like "*prod1*" Or "*prod2*" Then
Range("W2").Offset(i, 0).Value = "Segment1"

Currently I get a type mismatch error on the first of the lines shown here.
Any suggestions?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default Combining multiple like's with Or?

Thanks Dave. the first of the two works. I was just trying to cut more
corners than was allowed. :)

"Dave Peterson" wrote:

If Range("H2").Offset(i, 0).Value Like "*prod1*" _
Or Range("H2").Offset(i, 0).Value Like "*prod2*" Then

or maybe...

If lcase(Range("H2").Offset(i, 0).Value) Like "*prod1*" _
Or lcase(Range("H2").Offset(i, 0).Value) Like "*prod2*" Then


StumpedAgain wrote:

I'm trying to categorize certain products into one of three segments based on
their name. Since I have about 100 products, I'd rather not write a "like"
statement for each and every product. Is there a way to combine them so I
can do something like the following?

If Range("H2").Offset(i, 0).Value Like "*prod1*" Or "*prod2*" Then
Range("W2").Offset(i, 0).Value = "Segment1"

Currently I get a type mismatch error on the first of the lines shown here.
Any suggestions?


--

Dave Peterson

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
combining multiple columns from multiple files osiris73 Excel Discussion (Misc queries) 2 January 17th 07 03:30 AM
Help combining multiple columns into one [email protected] Excel Discussion (Misc queries) 8 December 28th 06 09:49 PM
Combining multiple worksheets tina Excel Worksheet Functions 0 September 29th 06 09:48 AM
Combining multiple tabs into one. [email protected] Excel Discussion (Misc queries) 1 July 19th 06 07:15 PM
Combining Text from multiple cells under multiple conditions KNS Excel Worksheet Functions 2 June 15th 05 11:00 PM


All times are GMT +1. The time now is 12:03 PM.

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"