Sub
TabelleAusMehrerenDateienEinlesen()
Dim
Zieldatei
As
Object
Dim
Quelldatei
As
Object
Dim
Pfad
As
String
Dim
Datei
As
String
Application.ScreenUpdating =
False
Application.DisplayAlerts =
False
Set
Zieldatei = Workbooks(
"Mappe1"
)
Pfad = "C:\Desktop\Auswertungen\Rohdaten\"
Datei = Dir(
CStr
(Pfad &
"*.xl*"
))
Do
While
Datei <>
""
Set
Quelldatei = Workbooks.Open(Pfad & Datei,
False
,
True
)
Quelldatei.Sheets(
"1 Kumulation"
).Copy after:=Zieldatei.Sheets(Zieldatei.Sheets.Count)
On
Error
Resume
Next
Zieldatei.Sheets(Zieldatei.Sheets.Count).Name = Datei
If
Err.Number <> 0
Then
Err.Number = 0
Err.Clear
End
If
On
Error
GoTo
0
Quelldatei.Close
False
Datei = Dir()
Loop
Call
SpaltenLoeschen
Application.ScreenUpdating =
True
Application.DisplayAlerts =
True
MsgBox
"Die Rohdaten sind vorbereitet!"
, vbInformation + vbOKOnly,
"Hinweis!"
Set
Zieldatei =
Nothing
Set
Quelldatei =
Nothing
Set
Quelltabelle =
Nothing
End
Sub
Sub
SpaltenLoeschen()
Dim
Quelltabelle
As
Worksheet
For
Each
Quelltabelle
In
ActiveWorkbook.Worksheets
Quelltabelle.Activate
If
(ActiveSheet.Range(
"A1"
).Value =
"Kumulation"
)
Then
Quelltabelle.Range(
"A:B"
).
Select
Selection.Delete Shift:=x1ToLeft
End
If
Next
Quelltabelle
End
Sub