VBA/Macro Check for Filtered rows IF(function) help

Psygrrl88

New Member
Joined
Dec 6, 2021
Messages
14
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
So - I am trying to have the macro check to see if there are filtered rows and if there aren't to display a message box that there isn't an error, and skip to the next check. However, I can't figure out what the IF function should be. I have tried ListObject("Table1"), ListObjects("Table1"), and ActiveSheet.ListObjects("Table1") and just referring to the worksheet as you can see in the example below. The worksheet option and the ListObject option both "work" but return no errors even though it has filtered to a set of 3 rows with the specified error.

ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=52, Criteria1:= _
"="
If Worksheet("Auto Census Report").AutoFilterMode = False Then
MsgBox "No Errors Edit 1"
ActiveSheet.ShowAllData
GoTo Edit2

End If
Range("A2").Select
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:= _
">0"
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Edits Sheet").Select
Range("A2").Select
ActiveSheet.Paste
ActiveCell.Offset(0, 3).Select
ActiveCell.FormulaR1C1 = "Demographics"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "1"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "Gender = Blank"
Sheets("Auto Census Report").Select
ActiveSheet.ShowAllData
Edit2:
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=56, Criteria1:= _
"="
If ActiveSheet.ListObjects("Table1").AutoFilterMode = False Then
MsgBox "No Errors Edit 2"
ActiveSheet.ShowAllData
GoTo EndProc

End If
Range("A2").Select
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:= _
">0"
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("Edits Sheet").Select
Range("A2").Select
Selection.End(xlDown).Range("A2").Select
ActiveSheet.Paste
ActiveCell.Offset(0, 3).Select
ActiveCell.FormulaR1C1 = "Demographics"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "2"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "Age = Blank"
Sheets("Auto Census Report").Select
ActiveSheet.ShowAllData
EndProc:
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Check the Autofiltermode and then check for hidden rows

VBA Code:
Sub CheckHiddenRows()
  Dim Sht As Worksheet
  Dim HidCnt As Long
  
  Set Sht = Sheets("Sheet9")
  If Sht.AutoFilterMode = True Then                                 'Returns True if Autofilter is on
    HidCnt = Sht.Rows.Count - Sht.Range("A:A").SpecialCells(xlCellTypeVisible).Count
    If HidCnt > 0 Then
      MsgBox "There are " & HidCnt & " hidden rows"
    End If
  End If
  
End Sub
 
Upvote 0
Solution
Check the Autofiltermode and then check for hidden rows

VBA Code:
Sub CheckHiddenRows()
  Dim Sht As Worksheet
  Dim HidCnt As Long
 
  Set Sht = Sheets("Sheet9")
  If Sht.AutoFilterMode = True Then                                 'Returns True if Autofilter is on
    HidCnt = Sht.Rows.Count - Sht.Range("A:A").SpecialCells(xlCellTypeVisible).Count
    If HidCnt > 0 Then
      MsgBox "There are " & HidCnt & " hidden rows"
    End If
  End If
 
End Sub
Thank you so much! works like a charm!
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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