AW: VBA Filter setzen
24.05.2019 13:41:15
Klaus
Hi Emre,
mit folgendem Code bekomme ich ausschließlich in Spalte A einen Autofilter:
Sub ResetAutofilter()
'example caller for the Autofilter Makro below
Dim iColFirst As Integer
Dim iColLast As Integer
Dim wksMySheet As Worksheet
Dim lRowFirst As Long
Set wksMySheet = Sheets("Tabelle1") 'sheet where this shall apply
iColFirst = 1 'from column X (A=1,B=2...)
iColLast = 1 'to column X
lRowFirst = 1 'start in this row
Call DoResetAutofilter(wksMySheet, iColFirst, iColLast, lRowFirst)
End Sub
Sub DoResetAutofilter(wksMySheet As Worksheet, iColFirst As Integer, iColLast As Integer, _
lRowFirst As Long)
'* in case a user used another autofiler, this makro resets the autofilter to where needed.
Dim lRowLast As Long
With wksMySheet
lRowLast = .Cells(.Rows.Count, iColFirst).End(xlUp).Row
If .AutoFilterMode Then .Cells.AutoFilter 'Turns OFF Autofilter, if any
.Range(.Cells(lRowFirst, iColFirst), .Cells(lRowLast, iColLast)).AutoFilter 'Turns ON _
Autofilter on given range
End With
End Sub
LG,
Klaus M.