PC Review


Reply
Thread Tools Rate Thread

Code to Ignore Certain Cases in a Looping Function

 
 
=?Utf-8?B?YWRhbWJ1c2g0MjQyQGhvdG1haWwuY29t?=
Guest
Posts: n/a
 
      7th Sep 2007
I had a VBA expert create a program for me, and it has worked perfectly for
months. However, recently I found there was an error because at a certain
point the program excludes certain inputs that meet a certain criteria. The
exact code is:
If Left$(Instrument$, 3) <> "SPX" Then
The problem is there is one scenario where the instrument starts with "SPX"
but I don't want to exclude it. There are twelve different strings that
might start with SPX, is there anyway to specify the first four letters, and
exclude SPXJ, SPXK, SPXG, SPXH, etc? I tried listing all these scenarios
where "SPX" currently is and putting "or" between them, but I keep getting
errors. ANy ideas?

Thanks

Adam Bush
 
Reply With Quote
 
 
 
 
=?Utf-8?B?YmFybmFiZWw=?=
Guest
Posts: n/a
 
      7th Sep 2007
You don't say which 4th letter you want to keep so I am putting in Z

If Left$(Instrument$, 3) <> "SPX" or left$(Instrument$,4) = "SPXZ" Then

Peter Richardson

"(E-Mail Removed)" wrote:

> I had a VBA expert create a program for me, and it has worked perfectly for
> months. However, recently I found there was an error because at a certain
> point the program excludes certain inputs that meet a certain criteria. The
> exact code is:
> If Left$(Instrument$, 3) <> "SPX" Then
> The problem is there is one scenario where the instrument starts with "SPX"
> but I don't want to exclude it. There are twelve different strings that
> might start with SPX, is there anyway to specify the first four letters, and
> exclude SPXJ, SPXK, SPXG, SPXH, etc? I tried listing all these scenarios
> where "SPX" currently is and putting "or" between them, but I keep getting
> errors. ANy ideas?
>
> Thanks
>
> Adam Bush

 
Reply With Quote
 
=?Utf-8?B?YWRhbWJ1c2g0MjQyQGhvdG1haWwuY29t?=
Guest
Posts: n/a
 
      7th Sep 2007
Peter,

Thank you very much for your help. I thought for some reason I had to list
the strings to exclude, not to include.

Thanks Again,

Adam Bush

"barnabel" wrote:

> You don't say which 4th letter you want to keep so I am putting in Z
>
> If Left$(Instrument$, 3) <> "SPX" or left$(Instrument$,4) = "SPXZ" Then
>
> Peter Richardson
>
> "(E-Mail Removed)" wrote:
>
> > I had a VBA expert create a program for me, and it has worked perfectly for
> > months. However, recently I found there was an error because at a certain
> > point the program excludes certain inputs that meet a certain criteria. The
> > exact code is:
> > If Left$(Instrument$, 3) <> "SPX" Then
> > The problem is there is one scenario where the instrument starts with "SPX"
> > but I don't want to exclude it. There are twelve different strings that
> > might start with SPX, is there anyway to specify the first four letters, and
> > exclude SPXJ, SPXK, SPXG, SPXH, etc? I tried listing all these scenarios
> > where "SPX" currently is and putting "or" between them, but I keep getting
> > errors. ANy ideas?
> >
> > Thanks
> >
> > Adam Bush

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      7th Sep 2007
If I am not mistaken, your suggested If-Then statement can be replaced by
this one...

If Not Instrument$ Like "SPX[!Z]*" Then

Rick


"barnabel" <(E-Mail Removed)> wrote in message
news:6B3CF90A-4AA5-49C7-BCA1-(E-Mail Removed)...
> You don't say which 4th letter you want to keep so I am putting in Z
>
> If Left$(Instrument$, 3) <> "SPX" or left$(Instrument$,4) = "SPXZ" Then
>
> Peter Richardson
>
> "(E-Mail Removed)" wrote:
>
>> I had a VBA expert create a program for me, and it has worked perfectly
>> for
>> months. However, recently I found there was an error because at a
>> certain
>> point the program excludes certain inputs that meet a certain criteria.
>> The
>> exact code is:
>> If Left$(Instrument$, 3) <> "SPX" Then
>> The problem is there is one scenario where the instrument starts with
>> "SPX"
>> but I don't want to exclude it. There are twelve different strings that
>> might start with SPX, is there anyway to specify the first four letters,
>> and
>> exclude SPXJ, SPXK, SPXG, SPXH, etc? I tried listing all these scenarios
>> where "SPX" currently is and putting "or" between them, but I keep
>> getting
>> errors. ANy ideas?
>>
>> Thanks
>>
>> Adam Bush


 
Reply With Quote
 
=?Utf-8?B?YmFybmFiZWw=?=
Guest
Posts: n/a
 
      7th Sep 2007
Quite true but I don't want to have to teach and debug somebody else's
regular expressions if they don't know what they are.

"Rick Rothstein (MVP - VB)" wrote:

> If I am not mistaken, your suggested If-Then statement can be replaced by
> this one...
>
> If Not Instrument$ Like "SPX[!Z]*" Then
>
> Rick
>
>
> "barnabel" <(E-Mail Removed)> wrote in message
> news:6B3CF90A-4AA5-49C7-BCA1-(E-Mail Removed)...
> > You don't say which 4th letter you want to keep so I am putting in Z
> >
> > If Left$(Instrument$, 3) <> "SPX" or left$(Instrument$,4) = "SPXZ" Then
> >
> > Peter Richardson
> >
> > "(E-Mail Removed)" wrote:
> >
> >> I had a VBA expert create a program for me, and it has worked perfectly
> >> for
> >> months. However, recently I found there was an error because at a
> >> certain
> >> point the program excludes certain inputs that meet a certain criteria.
> >> The
> >> exact code is:
> >> If Left$(Instrument$, 3) <> "SPX" Then
> >> The problem is there is one scenario where the instrument starts with
> >> "SPX"
> >> but I don't want to exclude it. There are twelve different strings that
> >> might start with SPX, is there anyway to specify the first four letters,
> >> and
> >> exclude SPXJ, SPXK, SPXG, SPXH, etc? I tried listing all these scenarios
> >> where "SPX" currently is and putting "or" between them, but I keep
> >> getting
> >> errors. ANy ideas?
> >>
> >> Thanks
> >>
> >> Adam Bush

>
>

 
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
IF function for two columns in diffent cases =?Utf-8?B?cHRfbGlseQ==?= Microsoft Excel Programming 4 25th Oct 2007 12:32 AM
Calling macros, looping function? Can this code be written more efficiently? Punsterr Microsoft Excel Programming 4 7th Oct 2005 07:16 PM
Change looping process to ignore certain sheets Rob Microsoft Excel Programming 6 16th May 2005 07:03 PM
GCD Function doesn't work in some cases =?Utf-8?B?R0NEX0RpbGVtbWE=?= Microsoft Excel Worksheet Functions 5 8th Nov 2004 08:18 PM
Using Cases in Code David Microsoft Excel Programming 1 29th Sep 2003 03:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:04 PM.