PC Review


Reply
Thread Tools Rate Thread

Combining multiple like's with Or?

 
 
StumpedAgain
Guest
Posts: n/a
 
      25th Jun 2008
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?

 
Reply With Quote
 
 
 
 
Sam Wilson
Guest
Posts: n/a
 
      25th Jun 2008
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?
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      25th Jun 2008
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 With Quote
 
StumpedAgain
Guest
Posts: n/a
 
      25th Jun 2008
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?
> >

 
Reply With Quote
 
StumpedAgain
Guest
Posts: n/a
 
      25th Jun 2008
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining multiple sheets Dallman Ross Microsoft Excel Misc 14 1st Jul 2007 03:44 PM
RE: combining multiple columns from multiple files =?Utf-8?B?RXhjZWxOb3ZpY2U=?= Microsoft Excel Misc 0 17th Jan 2007 03:30 AM
Re: Combining multiple files Suzanne S. Barnhill Microsoft Word Document Management 1 22nd Dec 2006 04:09 AM
Combining multiple lists into one ! =?Utf-8?B?QWRhbTE5NA==?= Microsoft Excel Worksheet Functions 0 19th Jun 2006 02:06 PM
Combining Text from multiple cells under multiple conditions =?Utf-8?B?S05T?= Microsoft Excel Worksheet Functions 2 15th Jun 2005 11:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:37 PM.