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

Hi Rory,

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.


. Ah …... From wot you said I can see that My B number increasing makes the formula look for the row offset by that amount.
. For example, By B3 = name 10 as criteria, - it looks for example for where the next one is name 10 so returns the name 9, and so on. This explains again my results in criteria 1 , criteria 2 and the new criteria 4 from pgc.


… the rest , I am not getting there.., yet

Alan
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Re: Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003 SOLVED

Sorry, I was not clear

You posted




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.

.......

.. I may have got that Bit. I really need to sleep on it and start again from the beginning, thangs again

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

… Don’t hold your Breath… but I think the mad lad may have got it at last….
.AdvancedFilter with Formula Criteria and Crazy Range Referencing
Aka. “.Advancedally Filtering” With offset Row criteria

. This ( I think ) is how the VBA Advanced Filter “works” in an example such as mine:
a) - VBA “goes sequentially through” each line of the Range to be “.Advancedally Filtered” (In my example the Range was A1:B10
b)- (First Row is reserved for headings. An important point but not too relevant to my “problem”. In the simplest form an usage of the Advanced Filter it is important that Headings in the Range to be “.Advancedally Filtered” and the range for the Filtered Output and the criteria range must have the headings exactly spelt the same. In the use of the formula in the criteria range a heading should still be there. It’s actual value however loses it’s significance and should, in fact, not be the same as any of the other Range headings )
c)- So let’s talk about this sequential progression through my rows. We will call them Hitlerations in honor to my adopted Fatherland. . (In my case there are 9 Hitlerations ( not 10, - we start at row 2 because row 1 is used for headings )
d)- At each Hitleration all the criteria is checked.
e)- Conventionally, and in all sane applications, a criteria formula is referencing cells in the original Range to be “.Advancedally Filtered” for and in each of the rows. So for all normal and sane application it would be adequate to syntaxly except just a column reference. In my example a B would have been logically thought to be sufficient. This would then apply by every Hitleration to the column of the cell in the row of that Hitleration.
f)- Unfortunately the convention is to follow the Letter for the Column by a number equal to that for the first row in the Range to be “.Advancedally Filtered” ( In my case 2** ) . This convention resulted in me coming up with the idea to change it, and see what happens. Unfortunately…
g) - At each Hitleration (all) the criteria is checked. Choosing for example to use B4 rather than B2 (My Range to be “.Advancedally Filtered” was A1:B10, so Reserving / using Row 1 for the headers would conventionally have _2 in a criteria formula**) means that the criteria is actually checked out in the row which is 2 rows up in the Range to be “.Advancedally Filtered” . But importantly the B cell that will be selected for the Filtered output Range will be that in the Hitleration Row. In the case of the first Hitleration 2.
h) - Every subsequent Hitleration will again return the appropriate value from the row of the Hitleration, if the criteria is met two rows up in the Range to be “.Advancedally Filtered” . This clearly explains my experimental results better than my dopey idea of the Range to be “.Advancedally Filtered” being pulled two rows down!!. ( I blame A.Einstein at this point, for sticking this mad idea in my head that everything is relative, ( relatively speaking ) ). This all easily and fully explains my results in Code Criteria 1
i) - For my Code Criteria 2 using 2 criteria cells the results are simply a combination of Code Criteria 1 and a normal formula ( that for getting at name 8 )
- The big mis – understanding on my behalf is that Rory and pgc were explaining very clearly my crazycriteriacrazy code 2 and I was referring to my criteria code 2, which was my experiments changing the B? from B2 through to B10 at the start of Post # 24 , rather than my crazy criteria crazy experiments later in that post with the B4 = name 10 and B2 = name 10 to get correspondingly out name 8 and name 10 (The problem as always was that I make my Threads too long and therefore too difficult to read. ( I blame Peter_ss for his absence for that #### )
J) - Coming back to my code criteria 3. The “mystery” is ( was:- ) the missing name 8 after B? = name 10 exceeds B4. If we understand the theory up until now, (If not go back now to the start and read again……. Ready?....... OK: - …….
. …….. The criteria B2 = name 8 returns name 8 when the formula is applied to the 7th Hitleration which is that for row 8 (remember first Hitleration is for row 2 as row 1 is used for headings ). After B_ exceeds B4 this Hitleration don’t work as the offset goes 3 bits up or more which is out of the Range to be “.Advancedally Filtered” . I couldn’t and can’t physically see or experience this error / formula failure, so totally missed it. - Luckily people who know told me or in the case of pgc could prove it with the formula mod which I applied in criteria code 4 , post # 28 – there the error for B? = name 10 is suppressed allowing the formula to still return name 8 from the B2 = name 8 part. Again I missed this initially as Rory and pgc were referring to the last experiments in the Thread. ( the crazycriteriacrazy codes and experiments not the initial criteriacode codes and experiments from the beginning of the Thread. )
k) - The Final problem from post #24 with my getting name 8 and name 10 using the criteria of B4 = name 10 and B2 = name 10 is now obvious to me. As clearly explained and demonstrated to me, the problem lies with B2 getting at name 10 with the B2 = name 10 part as at the 9th Hitleration the B4 = name 10 part causes the whole formula to crash. Again this is overcome by pgc error suppressor.
.

. So that Is it. ( I think)….

. As noted the problem lies partly with Dr. A.Einstein for distracting me with his crazy Theories, relatively speaking.
. The problem also lies with Peter_ss who has not in recent months been there to ignore my normal Threads or to warn me for my long rambling ones. I only hope Peter_ss is OK and just taking a well earned rest. I hope he comes back soon. His steadying influence ( not too mention his great codes and some amazing formulas ) are greatly missed. - In the last months I have been posting some ridiculously long Threads and really insanely long codes in the code windows which I fear could ultimately crash the forum Software. ( In addition it would be nice if he came back and took care of the “About the Board” Sub Forum , where since his absence many important questions have gone unanswered.
. ( If it helps to bring you back Peter_ss, I will sacrifice myself and promise to leave ( only returning when specifically asked to answer threads ) )

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

@ pgc,
I just tried to PM you to say thanks for your efforts here, but your in Box is full
Alan
 
Upvote 0
Re: Using CriteriaRange to exclude blank cells in a Range with AdvancedFilter XLS2003 SOLVED

Hi Alan. I'm glad it helped. Cheers!
 
Upvote 0

Forum statistics

Threads
1,215,929
Messages
6,127,748
Members
449,402
Latest member
jvivo3

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