AW: Autofilter-gefundene Einträge in Tab schreiben
02.05.2017 10:40:49
UweD
Hallo
Sub Filtern()
Dim TB1, TB2
Dim SP As Integer, EZ As Integer, LR As Long
Dim FFinde As String, ZielSP As Integer, QuellSP As Integer
Set TB1 = Sheets("Tabelle1")
Set TB2 = Sheets("Tabelle2")
SP = 1 'Spalte A
EZ = 2 'erste Zeile mit Daten
QuellSP = 14 'Spalte N
ZielSP = 1
FFinde = "2016"
If TB1.AutoFilterMode Then TB1.AutoFilterMode = False ' Autofilter ausschalten
LR = TB1.Cells(TB1.Rows.Count, SP).End(xlUp).Row 'letzte Zeile der Spalte
TB1.Columns(SP).AutoFilter Field:=1, Criteria1:=FFinde
If WorksheetFunction.CountIf(TB1.Columns(SP), FFinde) > 0 Then
'Reset
TB2.Columns(ZielSP).ClearContents
'kopieren
TB1.Range(TB1.Cells(EZ, QuellSP), TB1.Cells(LR, QuellSP)).Copy TB2.Cells(1, ZielSP)
'Duplikate raus
TB2.Columns(ZielSP).RemoveDuplicates Columns:=1, Header:=xlNo
Else
MsgBox "Keine Daten für '" & FFinde & "' gefunden"
End If
End Sub
LG UweD