Advance Filter on cells with formula

samahiji

Board Regular
Joined
Oct 6, 2015
Messages
82
Office Version
  1. 2019
Platform
  1. Windows
Hi
All cells in my sheet contains formula. I'm trying to use the advance filter to filter out the non blank cells "<>". However, it seems that The advance filter doesn't recognize cell as empty while it has a formula.

I'm using the following VBA:
VBA Code:
Sub CreateAdvancedFilter()
   Dim rngDatabase As Range
   Dim rngCriteria As Range
'define the database and criteria ranges
   Set rngDatabase = Sheets("Details").Range("A1:BS2700")
   Set rngCriteria = Sheets("ADF").Range("A1:BS2")
'filter the database using the criteria
   rngDatabase.AdvancedFilter xlFilterInPlace, rngCriteria
   Sheets("Details").Activate
End Sub
Any thought?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
The Advanced Filter feature does not recognize cells with formulas as blank. To filter for non-blank cells that contain formulas, you can use a helper column that checks if the cell has a value or not.

Here's an example of how to do this:

  1. Insert a new column in your sheet.
  2. In the first cell of the new column, enter the formula: =IF(ISBLANK(A1),"",IFERROR(1/(1/A1),""))
  3. Copy the formula down to the bottom of your data range.
  4. Select the entire data range including the new column.
  5. Use the Advanced Filter feature to filter for values greater than 0 in the new column.
  6. Delete the helper column once you have applied the filter.
In your VBA code, you can modify the range for the database to include the helper column you just created. For example, if the helper column is in column C, you can update the range to be "A1:C10000".
 
Upvote 0
Thanks a lot. Is it possible to have that helper column imbedded in vba? It is difficult to insert a helper column in my dataset.
or can you modify the above functionto be imbedded in my function below:
Excel Formula:
=IFNA(VLOOKUP($A2,Test!$B:$G,6,FALSE),"")
 
Upvote 0
One way to get around this issue is to modify your VBA code to copy the range with formulas to a temporary range, replace all formulas with their values, and then apply the Advanced Filter to the temporary range.

Try this.

VBA Code:
Sub CreateAdvancedFilter()

Dim rngDatabase As Range
Dim rngCriteria As Range
Dim rngTemp As Range

Set rngDatabase = Sheets("Details").Range("A1:BS2700")
Set rngCriteria = Sheets("ADF").Range("A1:BS2")

Set rngTemp = Sheets("Details").Range("BX1")
rngDatabase.Copy
rngTemp.PasteSpecial xlPasteValues

rngTemp.AdvancedFilter xlFilterInPlace,rngCriteria

rngTemp.Copy
rngDatabase.PasteSpecial xlPasteValues

rngTemp.ClearContents

Sheets("Details").

Activate End Sub

Note: The temporary range (in this case, "BX1") should be an unused range on the sheet. If "BX1" is already in use, you can modify the code to use a different range.
 
Upvote 0
There are various ways round it. If you are filtering text values for example, you could use ?* as the criterion, rather than <> If the values could be text or numbers in the same column then you can either use formula criteria or use two rows - one for the text criteria and one for the numbers.
 
Upvote 0
Solution
There are various ways round it. If you are filtering text values for example, you could use ?* as the criterion, rather than <> If the values could be text or numbers in the same column then you can either use formula criteria or use two rows - one for the text criteria and one for the numbers.
RoryA
Perfect! It was easy & quick way to solve the issue :)

I wish if you elaborate more on using formula criteria, what it mean (Give examples if possible), because I have noticed when two rows or more were used the filtering speed is affected.
 
Upvote 0
To use a formula for the criterion you need a header cell that does not match any of the headers in your table, then you write a formula based on the first row in your data using relative referencing. So for example, if you wanted to test for cells that contain something in column A, your criterion formula might be:

Excel Formula:
=LEN(A2)>0

The advanced filter will then evaluate this formula against every row in column A.
 
Upvote 0

Forum statistics

Threads
1,223,714
Messages
6,174,052
Members
452,542
Latest member
Bricklin

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