VBA Filter Blank Cells filters ALL cells in table

Xipha

New Member
Joined
Oct 29, 2013
Messages
16
I am using this line of code

ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:="<>"

Which according to all the forums should filter out all (and only) the blank values. On my sheet it filters ALL of the cells in the table so there are no rows showing, despite having ~50 with a value in them. Could this be due to the cells having a formula in them and not just a value? Any suggestions on how to fix this problem?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
That will only filter blank cells, regardless of whether they have a formula or not.
If it's hiding all rows, then there is something else going on.
 
Upvote 0
What formula do you have in the first column of your table?
 
Upvote 0
Code:
IFERROR(INDEX(Results,MATCH($A6,LabIDRange,0),MATCH(SoilSalinity[[#Headers],[Sample ID]],Results[#Headers],0)),"")

It's a table that is a subset of data from a master table that I am trying to automate the print setup. So there is a pivot table that updates with sample ID numbers that can be filtered based on certain parameters, and then the table adjacent to it looks up the values in the pivot table to pull out the relevant data for printing. Whenever the worksheet is activated it will run a code that will update the pivot table, and then filter out all of the extra blank rows I included in the table to make sure if the pivot table grew then the table would still pick up the extra data. It will then update the number of rows to print on the top of each page as well, but I haven't finished that code yet.

VBA Code:
Private Sub Worksheet_Activate()

Dim lo As ListObject
Dim iCol As Long
Dim SelectedCell As Range
Dim TableName As String

Dim FirstGuideRow As Long
Dim LastGuideRow As Long

ThisWorkbook.RefreshAll

Cells(5, 7).Select
Set SelectedCell = ActiveCell

On Error GoTo NoTableSelected
TableName = SelectedCell.ListObject.Name
Set lo = ActiveSheet.ListObjects(TableName)

iCol = lo.ListColumns(1).Index

lo.Range.AutoFilter Field:=iCol, Criteria1:=” <> ”

FirstGuideRow = Range("A:A").Find("*_*").Row - 1
LastGuideRow = Application.WorksheetFunction.CountIf(Range("A:A"), "*_*") + Range("A:A").Find("*_*").Row - 1


Cells(1, 1).Select

Exit Sub
NoTableSelected:
  MsgBox "There is no Table currently selected!", vbCritical

End Sub
 
Upvote 0
This is a partial screenshot of what the table looks like

Annotation 2019-12-19 105019.jpg
 
Upvote 0
The criteria looks wrong on this line
Rich (BB code):
lo.Range.AutoFilter Field:=iCol, Criteria1:=” <> ”
The quotes are of the wrong type, it should be "<>"
 
Upvote 0
So I randomly put a space after the equal sign and then pasted "<>" from your message above and suddenly it worked. I'm glad I spent 2 days trying to figure that out ?‍♀️
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

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