Romano_odK
Active Member
- Joined
- Jun 4, 2020
- Messages
- 380
- Office Version
- 365
- Platform
- Windows
Good afternoon,
In the below code I filter in my case "warehouse 1", but when for some reason this already has been done I get an error message. Is there a way to avoid this, beside not pushing the button. So somekind of warning or message instead of an error.
Thank you for your time and have a great day.
Romano
In the below code I filter in my case "warehouse 1", but when for some reason this already has been done I get an error message. Is there a way to avoid this, beside not pushing the button. So somekind of warning or message instead of an error.
Thank you for your time and have a great day.
Romano
VBA Code:
Private Sub FilterMag1_Click()
Range("Locatie[[#Headers],[Magazijn]]").Select
ActiveSheet.ListObjects("Locatie").Range.AutoFilter Field:=8, Criteria1:= _
"1"
Dim r As Range, q As Range, a As Range, b As Range
Dim tbl As ListObject
Set tbl = ActiveSheet.ListObjects("Locatie")
Set q = tbl.DataBodyRange.Columns(1)
Set r = q.SpecialCells(xlCellTypeVisible)
tbl.AutoFilter.ShowAllData
r.EntireRow.Hidden = True
q.SpecialCells(xlCellTypeVisible).Rows.ClearContents
q.EntireRow.Hidden = False
tbl.Range.Sort Key1:=tbl.Range.Cells(1), Order1:=xlAscending, Header:=xlYes
'first blank row
Set a = tbl.Range.Cells(1).End(xlDown).Offset(1)
'last row
Set b = a.End(xlDown)
If Not Intersect(b, tbl.DataBodyRange) Is Nothing Then
Range(a, b).Rows.Delete xlUp
Else 'if there's only 1 blank row
a.Rows.Delete xlUp
End If
End Sub