AW: 2 Arbeitsblätter exportieren VBA
15.12.2022 11:15:06
Rudi
Hallo,
dann:
Option Explicit
Sub IndikatorenExportieren()
Dim dicIdentNo As Object, oDic
Dim lngLastRow As Long, lngRow As Long
Dim wks As Worksheet, wkbNeu As Workbook
Dim arrSheets
Dim arrDaten
Set dicIdentNo = CreateObject("Scripting.Dictionary")
arrSheets = Array("Angest.", "Sonst.")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'AutoFilter in Spalte A einrichten
For Each wks In ThisWorkbook.Sheets(arrSheets)
With wks
.Columns(1).AutoFilter
If Not .AutoFilterMode Then
.Columns(1).AutoFilter
End If
'Letzte Zeile ermitteln
lngLastRow = .Cells(Rows.Count, 1).End(xlUp).Row
'Alle Indikatoren ermitteln
For lngRow = 2 To lngLastRow
dicIdentNo(.Cells(lngRow, 1).Text) = 0
Next lngRow
End With
Next wks
'Jeden Indikator filtern und in neuer Arbeitsmappe speichern
For Each oDic In dicIdentNo
Set wkbNeu = Workbooks.Add(1)
ActiveSheet.Name = arrSheets(1)
wkbNeu.Worksheets.Add.Name = arrSheets(0)
For Each wks In ThisWorkbook.Sheets(arrSheets)
With wks
.Range("A1").AutoFilter Field:=1, Criteria1:=oDic
arrDaten = .Cells(1, 1).CurrentRegion.SpecialCells(xlCellTypeVisible)
With wkbNeu.Sheets(wks.Name)
.Cells(1, 1).Resize(UBound(arrDaten), UBound(arrDaten, 2)) = arrDaten
.Columns.AutoFit
.Range("A1").Copy
.Range("A1").PasteSpecial xlPasteFormats
End With
End With
Application.CutCopyMode = False
Next wks
With wkbNeu
.SaveAs _
Filename:=ThisWorkbook.Path & "\" & Replace(ThisWorkbook.Name, ".xlsm", "") & "_" & oDic, _
FileFormat:=xlOpenXMLWorkbook
.Close
End With
Set wkbNeu = Nothing
Next oDic
Application.Calculation = xlCalculationAutomatic
End Sub
Gruß
Rudi