Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default multiple qualifiers for If statements

If Cells(i, "e").Value = "CA" Then

I want to include all west coast accounts with the same if statement.

If Cells(i, "e").Value = "CA" Or "WA" Or "OR" Or "NV" Then -- this
of course isn't working. How would I get it to work?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default multiple qualifiers for If statements

if not iserror(application.matchCells(i, "e").Value ,
array("CA","WA","OR","NV"),0)) then
.....

Note: this is not case-sensitive: that might or might not matter for you...

Tim


"Matthew Dyer" wrote in message
...
If Cells(i, "e").Value = "CA" Then

I want to include all west coast accounts with the same if statement.

If Cells(i, "e").Value = "CA" Or "WA" Or "OR" Or "NV" Then -- this
of course isn't working. How would I get it to work?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default multiple qualifiers for If statements

On Nov 2, 7:49*pm, "Tim Williams" wrote:
if not iserror(application.matchCells(i, "e").Value ,
array("CA","WA","OR","NV"),0)) then
....

Note: this is not case-sensitive: that might or might not matter for you....

Tim

"Matthew Dyer" wrote in message

...



If Cells(i, "e").Value = "CA" Then


I want to include all west coast accounts with the same if statement.


If Cells(i, "e").Value = "CA" Or "WA" Or "OR" Or "NV" Then * -- this
of course isn't working. How would I get it to work?- Hide quoted text -


- Show quoted text -


I get an error saying "Wrong number of arguments or invalid property
assignments"...
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default multiple qualifiers for If statements

Should all be on one line (and I missed the opening parenthesis for Match())

Sub tester()
Dim rng As Range

Set rng = ActiveSheet.Range("A1")
If Not IsError(Application.Match(rng.Value, _
Array("CA", "WA", "OR", "NV"), 0)) Then

MsgBox "Value OK"

End If

End Sub


Tim


"Matthew Dyer" wrote in message
...
On Nov 2, 7:49 pm, "Tim Williams" wrote:
if not iserror(application.matchCells(i, "e").Value ,
array("CA","WA","OR","NV"),0)) then
....

Note: this is not case-sensitive: that might or might not matter for
you...

Tim

"Matthew Dyer" wrote in message

...



If Cells(i, "e").Value = "CA" Then


I want to include all west coast accounts with the same if statement.


If Cells(i, "e").Value = "CA" Or "WA" Or "OR" Or "NV" Then -- this
of course isn't working. How would I get it to work?- Hide quoted text -


- Show quoted text -


I get an error saying "Wrong number of arguments or invalid property
assignments"...


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default multiple qualifiers for If statements

On Nov 2, 9:54*pm, "Tim Williams" wrote:
Should all be on one line (and I missed the opening parenthesis for Match())

Sub tester()
Dim rng As Range

* * Set rng = ActiveSheet.Range("A1")
* * If Not IsError(Application.Match(rng.Value, _
* * * * * * * * * * * * * Array("CA", "WA", "OR", "NV"), 0)) Then

* * * * MsgBox "Value OK"

* * End If

End Sub

Tim

"Matthew Dyer" wrote in message

...
On Nov 2, 7:49 pm, "Tim Williams" wrote:





if not iserror(application.matchCells(i, "e").Value ,
array("CA","WA","OR","NV"),0)) then
....


Note: this is not case-sensitive: that might or might not matter for
you...


Tim


"Matthew Dyer" wrote in message


....


If Cells(i, "e").Value = "CA" Then


I want to include all west coast accounts with the same if statement.


If Cells(i, "e").Value = "CA" Or "WA" Or "OR" Or "NV" Then -- this
of course isn't working. How would I get it to work?- Hide quoted text -


- Show quoted text -


I get an error saying "Wrong number of arguments or invalid property
assignments"...- Hide quoted text -

- Show quoted text -


Works perfectly. Thanks for the help!

On a side note... Is it considered sloppy coding to use the same
method to build arrays within the if statements or should I build the
arrays in a public statement, then reference the arrays within the if
statements?


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default multiple qualifiers for If statements

If you are using the array in multiple places then you should probably code
a small function to encapsulate it:

Function TheStates()
TheStates=Array("CA", "WA", "OR", "NV")
End Function

t once then I wouldn't bother, but it really depends on the "target
audience" (in-house utility app vs. commercial code) and how much
maintenance you expect to be doing. The more maintenance, the more you want
to isolate variables into constants or methods.

Tim



"Matthew Dyer" wrote in message
...
On Nov 2, 9:54 pm, "Tim Williams" wrote:
Should all be on one line (and I missed the opening parenthesis for
Match())

Sub tester()
Dim rng As Range

Set rng = ActiveSheet.Range("A1")
If Not IsError(Application.Match(rng.Value, _
Array("CA", "WA", "OR", "NV"), 0)) Then

MsgBox "Value OK"

End If

End Sub

Tim

"Matthew Dyer" wrote in message

...
On Nov 2, 7:49 pm, "Tim Williams" wrote:





if not iserror(application.matchCells(i, "e").Value ,
array("CA","WA","OR","NV"),0)) then
....


Note: this is not case-sensitive: that might or might not matter for
you...


Tim


"Matthew Dyer" wrote in message


...


If Cells(i, "e").Value = "CA" Then


I want to include all west coast accounts with the same if statement.


If Cells(i, "e").Value = "CA" Or "WA" Or "OR" Or "NV" Then -- this
of course isn't working. How would I get it to work?- Hide quoted
text -


- Show quoted text -


I get an error saying "Wrong number of arguments or invalid property
assignments"...- Hide quoted text -

- Show quoted text -


Works perfectly. Thanks for the help!

On a side note... Is it considered sloppy coding to use the same
method to build arrays within the if statements or should I build the
arrays in a public statement, then reference the arrays within the if
statements?


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
Multiple Qualifiers HeatherMichelle Excel Discussion (Misc queries) 1 January 5th 10 03:54 AM
How do I set up an IF formula with multiple qualifiers? chubbs Excel Discussion (Misc queries) 4 September 10th 08 10:13 PM
How do I use 3 separate column qualifiers to sum? IF statements? Shahbaze Excel Worksheet Functions 1 September 18th 06 06:55 PM
Table lookup using multiple qualifiers TechMGR Excel Discussion (Misc queries) 1 January 11th 06 06:36 PM
If Statement with multiple qualifiers mworth01[_6_] Excel Programming 3 August 26th 05 04:30 PM


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

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

About Us

"It's about Microsoft Excel"