Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003

LolaM

New Member
Joined
Sep 7, 2011
Messages
24
OK guys, I am having trouble with the following...

In column A I have several cells containing data, which may have multiple entries of the same data. Along with this there are potentially blank cells.

I want to perform an AdvancedFilter on this column to take only the cells which have data, and copy a unique entry of each of these data elements to column B - in no particular order.

So for example if column A contains:
A1: Apple
A2: <blank>
A3: Orange
A4: <blank>
A5: Banana
A6: Apple
A7: Apple

Then running the AdvancedFilter would result in the following in column B
B1: Apple
B2: Orange
B3: Banana

ie. the blanks are removed and only one entry of identical entries in column A is copied to column B.

At the moment I can get the AdvancedFilter to copy the unique entries from col A to col B, but if <blank>cell A1 is blank, then cell B1 is <blank>blank, with the unique data in cells B2 downwards.

I *think* I should be looking at adding a CriteriaRange:= argument to the AdvancedFilter, but I'm struggling on how to write this to exclude blanks.

Any help you can offer would be greatly appreciated! Thanks in advance!</blank></blank></blank></blank>
 
Re: Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003 SOLVED

. …Ahh, sorry, the Pills are not working today - :oops:- I really most sort my brain out…:p:p I see the logic. It is obvious… <>MMG-561 allows everything other than <>MMG-561 , and <>MAE-745 allows everything other than <>MAE-745. The combination of the two allows everything as I am seeing!!

..............................................................................................

Hmm....

. This would be one very in - elegant work around… (An extra kopie of License plate column is required for every additional License plat number to be omitted like so..

Screen shot before running code:

Using Excel 2007
-
A
B
C
D
E
F
G
H
1
NumberPlateKopieNumberPlateNameNumberPlateNameNumberPlateKopieNumberPlateName
2
MIN-423MIN-423name 1<>MMG-561<>MAE-745
3
MDN-229MDN-229name 2
4
MMG-561MMG-561name 4
5
6
MDN-229MDN-229name 5
7
MDN-229MDN-229name 5
8
hdshghdshgname 8
9
MDN-229MDN-229name 9
10
MAE-745MAE-745name 10

<tbody>
</tbody>
VBAAdvancedFilterCriteria

<tbody>
</tbody>

Modified code:

Code:
[COLOR=blue]Sub[/COLOR] NumberplatesSimplified()
 
Range("A1:C10").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("D1:E10"), Unique:=False, CriteriaRange:=Range("F1:H2")
 
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]

Screenshot after running code:

Using Excel 2007
-
A
B
C
D
E
1
NumberPlateKopieNumberPlateNameNumberPlateName
2
MIN-423MIN-423name 1MIN-423name 1
3
MDN-229MDN-229name 2MDN-229name 2
4
MMG-561MMG-561name 4
5
MDN-229name 5
6
MDN-229MDN-229name 5MDN-229name 5
7
MDN-229MDN-229name 5hdshgname 8
8
hdshghdshgname 8MDN-229name 9
9
MDN-229MDN-229name 9
10
MAE-745MAE-745name 10

<tbody>
</tbody>
VBAAdvancedFilterCriteria

<tbody>
</tbody>

. I guess there may be some way to do this better, ( while still using the Advanced Filter Method ) for example by putting some sort of Boolean logic in one cell..
.. of the form

="<>MMG-561" AND ="<> MAE-745"

……Hmm..:confused:
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Re: Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003 SOLVED

You don't need to have a copy of the column. You can use the same header twice in the criteria range:


Excel 2010
ABCDEF
1NumberPlateNameNumberPlateNameNumberPlateNumberPlate
2MIN-423name 1MIN-423name 1<>MMG-561<>MAE-745
3MDN-229name 2MDN-229name 2
4MMG-561name 4MDN-229name 5
5MDN-229name 5MDN-229name 5
6MDN-229name 5hdshgname 8
7hdshgname 8MDN-229name 9
8MDN-229name 9
9MAE-745name 10
Sheet1


If you want t use a formula you need to clear the header from the criteria range:


Excel 2010
ABCDE
1NumberPlateNameNumberPlateName
2MIN-423name 1MIN-423name 1TRUE
3MDN-229name 2MDN-229name 2
4MMG-561name 4MDN-229name 5
5MDN-229name 5MDN-229name 5
6MDN-229name 5hdshgname 8
7hdshgname 8MDN-229name 9
8MDN-229name 9
9MAE-745name 10
Sheet2
Cell Formulas
RangeFormula
E2=AND(A2<>"MMG-561",A2<>"MAE-745")
 
Upvote 0
Re: Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003 SOLVED

You don't need to have a copy of the column. You can use the same header twice in the criteria range:
…………

. Thanks for that. I was seeing from my practicing that juggling around with the Headings, ( their positions etc. ) was possible and appeared to be a key useful characteristic of the Advanced Filter Method. I had not hit on to that idea of duplicating a criteria range heading as a means of giving a criteria row to get multiple “entry exclusion” criteria. So thanks for that Tip
--- so using your first screen shot from post #22 and the following code I achieve my desired results

Code:

Code:
[color=blue]Sub[/color] NumberplatesPoulsomMultiExclusion_DiplicateCriteriaHeading()
 
Range("A1:B9").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("C1:D9"), Unique:=False, CriteriaRange:=Range("E1:F2")
 
[color=blue]End[/color] [color=blue]Sub[/color]

Thanks..
………………………………………………………….

………


If you want to use a formula you need to clear the header from the criteria range:

Excel 2010
A
B
C
D
E
1
NumberPlate
Name
NumberPlate
Name
2
MIN-423
name 1
TRUE
3
MDN-229
name 2
4
MMG-561
name 4
5
MDN-229
name 5
6
MDN-229
name 5
7
hdshg
name 8
8
MDN-229
name 9
9
MAE-745
name 10

<thead>
</thead><tbody>
</tbody>
Sheet2




Worksheet Formulas
Cell
Formula
E2
=AND(A2<>"MMG-561",A2<>"MAE-745")

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

… Thanks for that. I was just getting into this idea. Again it was not in the contextures link, but by experimenting with various syntax in the criteria “FALSE And “TRUE” sometimes “popped up” in the cell!!. Following up from reviewing that link you gave did I hit on another similar contextures video:

https://www.youtube.com/watch?v=3hnNN0vciBQ

where something very similar is done. I was a little confused with the strange syntax need to remove ( or change ) the Heading, so it was very helpful that you applied / gave an exact solution to my requirement. Very helpful in getting the idea clear in my head!! ( I see now the logic to that requirement: I could include in the Boolean Bit other columns, such as in my example below. (Still a bit confusing that the syntax takes A2 and B2 rather than A? and C? as the criteria will be checked down for every column in the List Range. ).
. So for completeness a “Boolean Bit” example:

Before running any code:

<b>Excel 2007</b><table size=1 width="1" cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style=";">NumberPlate</td><td style=";">Name</td><td style=";">NumberPlate</td><td style=";">Name</td><td style=";">JumbledCriteriaReferrencing</td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style=";">MIN-423</td><td style=";">name 1</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;">WAHR</td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style=";">MDN-229</td><td style=";">name 2</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style=";">MMG-561</td><td style=";">name 4</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style=";">MDN-229</td><td style=";">name 5</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">6</td><td style=";">MDN-229</td><td style=";">name 5</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">7</td><td style=";">hdshg</td><td style=";">name 8</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">8</td><td style=";">MDN-229</td><td style=";">name 9</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">9</td><td style="color: #333333;;">MAE-745</td><td style="color: #333333;;">name 10</td><td style="text-align: right;color: #333333;;"></td><td style="text-align: right;color: #333333;;"></td><td style="text-align: right;color: #333333;;"></td></tr></tbody></table><p style="width:15em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #A6AAB6;border-top:none;text-align: center;background-color: #E0E0F0;color: #161120">VBAAdvancedFilterCriteria</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #A6AAB6"><thead><tr style=" background-color: #E0E0F0;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">E2</th><td style="text-align:left">=AND(<font color="Blue">A2<>"MMG-561",A2<>"MAE-745",B2<>"name 8"</font>)</td></tr></tbody></table></td></tr></table><br />

And after running code:

Using Excel 2007
-
A
B
C
D
E
1
NumberPlateNameNumberPlateNameJumbledCriteriaReferrencing
2
MIN-423name 1MIN-423name 1
=AND(A2<>"MMG-561",A2<>"MAE-745",B2<>"name 8")​
3
MDN-229name 2MDN-229name 2
4
MMG-561name 4MDN-229name 5
5
MDN-229name 5MDN-229name 5
6
MDN-229name 5MDN-229name 9
7
hdshgname 8
8
MDN-229name 9
9
MAE-745name 10
VBAAdvancedFilterCriteria
..
Code:
Code:
[color=blue]Sub[/color] NumberplatesPoulsomMultiExclusion_BooleanFormula()
 
Range("A1:B9").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("C1:D9"), Unique:=False, CriteriaRange:=Range("E1:E2")
 
[color=blue]End[/color] [color=blue]Sub[/color]

Thanks again Andrew for your generous help. Very grateful.
Alan Elston.

P.s.

. Thanks again for that contextures link. In fact the spreadsheet Advance Filter info there is very useful as it mirrors very closely the VBA Advanced Filter Method, (the info from pgc Post # 13 for example is also there and I had missed that elsewhere )
Indeed, from contextures.com one similar video ( not in that link so for anyone looking into this thread I give it here) …

https://www.youtube.com/watch?v=S0pXfzUW6C8

… this actually uses the macro recorder to produce a code of the form similar to those with which I have been experimenting with. It is very useful when someone with experience recommends a good source of info, as otherwise it can be very overwhelming the massive amount of info out there these days.
 
Upvote 0
Re: Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003 SOLVED

…………... (Still a bit confusing that the syntax takes A2 rather than A? or just A , as the criteria will be checked down for every column in the List Range. ). …….
……………….

… just feeding back some last madness here…, I was trying to find some logic to the B2 rather than B? syntax..

.. Consider this experiment: I consider various ways to Filter out Driver’s Names, using 3 different CriteriaRanges, all of which appear to give me the correct result, picking out either Driver name 10 or Driver Name 10 and Driver Name 8 depending on which of the 3 Criteria Ranges I choose to include in my code. The following screenshot , for example will pick out both Driver Names correctly using the second two of the accompanying codes given after the screenshot…

Screenshot ( using either of second 2 codes ):

Using Excel 2007
-
A
B
C
D
E
F
G
1
NumberPlateDriver NameNumberPlateDriver Name
CriteriaCode1​
CriteriaCode2​
CriteriaCode3​
2
MIN-423name 2hdshgname 8
=B2="name 10"​
=B2="name 8"​
=OR(B2="name 8",B2="name 10")​
3
MDN-229name 3MAE-745name 10
=B2="name 10"​
4
MDN-229name 4
5
MMG-561name 5
6
MDN-229name 6
7
MDN-229name 7
8
hdshgname 8
9
MDN-229name 9
10
MAE-745name 10

Codes:

Code:
[color=darkgreen]'[/color]
[color=blue]Sub[/color] Code_1_NumberplatesSingleNameSearch_BooleanFormula()
Range("A1:B10").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("E1:E2"), CopyToRange:=Range("C1:D10"), Unique:=[color=blue]False[/color]
[color=blue]End[/color] [color=blue]Sub[/color]
[color=blue]Sub[/color] Code_2_NumberplatesMultiNameSearch1_BooleanFormula()
Range("A1:B10").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("F1:F3"), CopyToRange:=Range("C1:D10"), Unique:=[color=blue]False[/color]
[color=blue]End[/color] [color=blue]Sub[/color]
Sub Code_3_NumberplatesMultiNameSearch2_BooleanFormula()
Range("A1:B10").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("G1:G2"), CopyToRange:=Range("C1:D10"), Unique:=[color=blue]False[/color]
[color=blue]End[/color] Sub
.

. I experimented with various combination of B?, that is to say B3 B4 etc.. rather than B2.
. A sub – set of my experiments involved for example changing B2 in =B2="name 10" to B2 B3 B4 …. Etc. The results for the Driver Names given for the three codes are summarized here

Using Excel 2007
B?=name 10​
Code 1Code 2Code 3
? Value​
Criteria1​
Criteria2​
Criteria3​
2​
10​
8 10​
8 10​
3​
9​
8 9​
8 9​
4​
8​
8​
8​
5​
7​
7 8​
7​
6​
6​
6 8​
6​
7​
5​
5 8​
5​
8​
4​
4 8​
4​
9​
3​
3 8​
3​
10​
2​
2 8​
2​
11​

. The logic appears to be that by increasing the cell reference for B by a particular offset value , sets backwards the referenced cell by a corresponding value.
. This gives an ( academically! ) interesting alternative criteria for picking out Driver Name 8 and 10 for code 2:

-
CrazyCriteriaCode2
=B2="name 10"​
=B4="name 10"​
……
. This logic can almost be applied to Code 3, but not quite. I cannot get at Driver name 8 and 10 with this criteria:

-
CrazyCriteriaCrazyCode3
=OR(B4="name 10",B2="name 10")​
Or this:
-
CrazyCriteriaCrazyCode3
=OR(B2="name 10",B4="name 10")​
. In both cases as I appear to be limited to referencing row 8. So I achieve this result:

-
-
C
D
1
NumberPlateDriver Name
2
hdshgname 8
3



– I could for example use the “crazy” criterion to get at name 7 and name 8.
Criteria:
-
CrazyCriteriaCrazyCode3
=OR(B2="name 7",B4="name 10")​
Result:
Using Excel 2007
-
C
D
1
NumberPlateDriver Name
2
MDN-229name 7
3
hdshgname 8

………………………………

… This was a somewhat academic experiment although I am wondering if there is some documented logic to the issues raised here. This could be an interesting insight into how VBA is working…

.. Anyone got any comments?

Alan.
 
Upvote 0
Re: Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003 SOLVED

The criteria cannot refer to cells outside the filter range. In your 2 cell criteria, the second criterion is invalid for the last two rows of the table, but the last row matches the first criterion so is included in the results. For the single formula criteria range, the whole formula is invalid for the last two rows, so neither are treated as matches.
 
Upvote 0
Re: Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003 SOLVED

Hi

Like Rory said you cannot get out of the filter range, or you'll get an error.

If you want you can filter that error in the criterion formula:

=OR(B2="name 10",IFERROR(B4="name 10",FALSE))
 
Upvote 0
Re: Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003 SOLVED

Hi Rory,

The criteria cannot refer to cells outside the filter range. …...

…. I am with that bit, matches my empirical Observations. Not sure about the rest….Going through the actual experiment I did. … ( It may not have been too clear exactly what I did – I actually changed the number after B in the criteria referring to name 10 )……
. - Increasing the number after B from it’s usual 2 to 3 then 4 then 5 etc. seems to have the effect of shifting the range up a line at a time but the criteria still looks in the same cell and so sees the next number down..
. - The results for criteriaCode1 (Column E) ties up with that.
. – For CriteriaCode2 (Column F) the second criteria (Cell F3) is therefore I expect duplicating the results from
criteriaCode1 (Column E). The first criteria ( Cell F2) works “normally” – there is no shifting of the range for that criteria and it always finds name 8
. – What appears to be happening in CriteriaCode3 (Column G) is that changing the B in part of the formula shifts the range up again so the second part of the formula duplicates the results of the last two again. – But Somehow the first part of the formula “goes with” the original range , still “working normally” giving the name 8. However as you may be suggesting , the range is truncated at 10 so after notching up 3 spaces the 8 is chopped off. So it is not found.

. I am not clear how the that ties up with the rest of what you said…..


….. In your 2 cell criteria, the second criterion is invalid for the last two rows of the table, but the last row matches the first criterion so is included in the results. …...

…. Maybe it does. It is just a difficult to clearly see what is happening. Exactly how VBA is referencing here may be unknown to anyone? I think I am at least seeing a logic to predict what would happen from my explanation.


. Thanks
Alan..
 
Upvote 0
Re: Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003 SOLVED

<o:p> </o:p>
Hipgc<o:p></o:p>
<o:p> </o:p>


Like Rorysaid you cannot get out of the filter range, or you'll get an error.

If youwant you can filter that error in the criterion formula:

=OR(B2="name10",IFERROR(B4="name 10",FALSE))
<o:p></o:p>
<o:p> </o:p>
…Thanks for your contribution. I do not see ( yet! ) what you are saying, or therelevance to what I am doing. I received no error in the results for my outputrange, just the results summarized in Post #24<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
. I did however try your Formula…<o:p></o:p>
<o:p> </o:p>
Using Excel 2007<o:p></o:p>
-
H
<o:p></o:p>
[tr][td]
1
[/td][td]
CriteriaCode4
[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
2
[/td][td]
=OR(B2="name8",IFERROR(B10="name10",FALSE))
[/td][/tr]<o:p></o:p>
VBAAdvancedFilterCriteria2
<o:p></o:p>

<o:p> </o:p>
<o:p> </o:p>
Withthis code: <o:p></o:p>
<o:p> </o:p>
Code:
[color=blue]Sub[/color]Code_4_NumberplatesMultiNameSearch2_BooleanFormula()<o:p></o:p>[/FONT][/COLOR]
[COLOR=gray][FONT=Verdana]Range("A1:B10").AdvancedFilterAction:=xlFilterCopy, CriteriaRange:=Range("H1:H2"),CopyToRange:=Range("C1:D10"), Unique:=[color=blue]False[/color]<o:p></o:p>[/FONT][/COLOR]
[COLOR=gray][FONT=Verdana][color=blue]End[/color][color=blue]Sub[/color]
<o:p></o:p>

<o:p> </o:p>
AndI did get different results, interesting results..<o:p></o:p>
<o:p> </o:p>
Using Excel 2007<o:p></o:p>
<o:p></o:p>
[tr][td][/td][td]
Names - Filtered by codes​
[/td][td]
[/td][td]
[/td][td]
[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
B?=name 10​
[/td][td]Code 1[/td][td]Code2[/td][td]Code 3[/td][td]Code4[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
? Value​
[/td][td]
Criteria1​
[/td][td]
Criteria2​
[/td][td]
Criteria3​
[/td][td]Criteria4[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
2​
[/td][td]
10​
[/td][td]
8 10​
[/td][td]
8 10​
[/td][td]
8 10​
[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
3​
[/td][td]
9​
[/td][td]
8 9​
[/td][td]
8 9​
[/td][td]
8 9​
[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
4​
[/td][td]
8​
[/td][td]
8​
[/td][td]
8​
[/td][td]
8​
[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
5​
[/td][td]
7​
[/td][td]
7 8​
[/td][td]
7​
[/td][td]
78​
[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
6​
[/td][td]
6​
[/td][td]
6 8​
[/td][td]
6​
[/td][td]
6 8​
[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
7​
[/td][td]
5​
[/td][td]
5 8​
[/td][td]
5​
[/td][td]
5 8​
[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
8​
[/td][td]
4​
[/td][td]
4 8​
[/td][td]
4​
[/td][td]
4 8​
[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
9​
[/td][td]
3​
[/td][td]
3 8​
[/td][td]
3​
[/td][td]
3 8​
[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
10​
[/td][td]
2​
[/td][td]
2 8​
[/td][td]
2​
[/td][td]
2 8​
[/td][/tr]<o:p></o:p>
<o:p> </o:p> [tr][td]
11​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]<o:p></o:p>
VBAAdvancedFilterCriteria2
<o:p></o:p>

<o:p> </o:p>
….I also note that for the one case of the number after B as 10 the usual value Falsein the criteria cell ( H2 ) does change to true.<o:p></o:p>
…Somehow it is now giving me results tying up with my “shifts the range” theory given to Roryin my Post #27, but my theory that therange is Truncated at 10 is no longer valid… <o:p></o:p>
<o:p> </o:p>
…I am struggling a bit now to understand but maybe I will return here with a clearhead later!!<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
Thanksagain for your inputs<o:p></o:p>
<o:p> </o:p>
Alan <o:p></o:p>
 
Last edited:
Upvote 0
Re: Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003 SOLVED

Your formula is applied to the data once for each data row, incrementing the relative row references by 1 each time. This when you come to the second last and last iterations, your B4 reference has increased to point to a cell outside the data table, which is invalid.
 
Upvote 0
Re: Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003 SOLVED

<o:p> </o:p>


…Thanks for your contribution. I do not see ( yet! ) what you are saying, or therelevance to what I am doing. I received no error in the results for my outputrange, just the results summarized in Post #24<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p><o:p></o:p>


Sorry, I was not clear

You posted





. This logic can almost be applied to Code 3, but not quite. I cannot get at Driver name 8 and 10 with this criteria:

-
CrazyCriteriaCrazyCode3
=OR(B4="name 10",B2="name 10")​

<tbody>
</tbody>

Or this:
-
CrazyCriteriaCrazyCode3
=OR(B2="name 10",B4="name 10")

<tbody>
</tbody>

. In both cases as I appear to be limited to referencing row 8. So I achieve this result:

-
-
C
D
1
NumberPlateDriver Name
2
hdshgname 8
3

<tbody>
</tbody>

What I was saying is that you can go around the reference error when the reference goes out of the table, if you use IsError().

With the criterion formula in E2: =OR(B2="name 10",IFERROR(B4="name 10",FALSE))

... you get both records, which I understood what what you wanted to test.


<table border="1" cellpadding="1" style="background:#FFF; border-collapse:collapse;border-width:2px;border-color:#CCCCCC;font-family:Arial,Arial; font-size:10pt" ><tr><th style="border-width:1px;border-color:#888888;background:#9CF " > </th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >A</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >B</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >C</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >D</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >E</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" width=30 >F</th></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>1</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">NumberPlate</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">Driver Name</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">NumberPlate</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">Driver Name</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">CriteriaCode1</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>2</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">MIN-423</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">name 2</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">hdshg</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">name 8</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:center;border-width: 1px;border-color:#888888; ">FALSE</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>3</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">MDN-229</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">name 3</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">MAE-745</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">name 10</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>4</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">MDN-229</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">name 4</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>5</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">MMG-561</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">name 5</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>6</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">MDN-229</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">name 6</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>7</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">MDN-229</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">name 7</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>8</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">hdshg</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">name 8</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>9</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">MDN-229</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">name 9</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>10</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">MAE-745</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">name 10</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>11</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td colspan=7 style="background:#9CF; padding-left:1em" > [Book1]Sheet2</td></tr></table>
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top