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
>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.