Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How Autofilter works?

I got the following code,

Set V_RangeNamePlus = Range(V_RangeNameTop, LastRowFilter1)
V_RangeNamePlus.AutoFilter

ws1.Range(V_RangeNameTop, LastRowFilter1).AutoFilter Field:=LcolNRPlus, Criteria1:=""
ws1.Range(V_RangeNameTop, LastRowFilter1).AutoFilter Field:=FirsWhiteColNr, Criteria1:="<>"

V_RangeNameWhite.Resize(V_RangeNamePlus.Rows.Count-1).SpecialCells(xlCellTypeVisible).Rows.ClearContents

V_RangeNamePlus.AutoFilter

My question is regarding the case when the Criteria 1 & 2 are not available for selection at all or just one of them, what this line of code does, or how the autofilter works in these case

V_RangeNameWhite.Resize(V_RangeNamePlus.Rows.Count-1).SpecialCells(xlCellTypeVisible).Rows.ClearContents 

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use on error resume next like this

On error resume next    'in case there are no visible rows

V_RangeNameWhite.Resize(V_RangeNamePlus.Rows.Count-1).SpecialCells(xlCellTypeVisible).Rows.ClearContents

On error goto 0

The perfect solution would be

Dim rgVisibleRows As Range

On Error Resume Next    'in case there are no visible Rows.
Set rgVisibleRows = V_RangeNameWhite.Resize(V_RangeNamePlus.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If Not rgVisibleRows Is Nothing Then
    rgVisibleRows.Rows.ClearContents
End If

as in the previous solution the error could also result from clearing the contents.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading