Nochmal XL4 für Erich G.
19.12.2005 08:15:09
Rainer
nachdem ich auf den alten Beitrag nicht mehr antworten kann, hier die rückmeldung. Ich habe es mit dem neuen Code versucht, jetzt liest er auch ein, aber bei folgender Zeile
Workbooks.Open FileName:=strVerz & "\" & strFile, UpdateLinks:=False
kommt die Meldung, möchten Sie die Datei erneut öffnen.
Sonst sieht es gut aus, was das Makro macht.
Gruß rainer
Ich füge nochmal den ganzen Makrotext ein.
Sub Kopie_aus_Mappen()
Dim strFile As String
Dim intSpZ%, intSp%
Dim wks As Worksheet, ii%, lngLast&
' Vorgaben
Const strVerz = "c:\umsatz" ' Quellverzeichnis
' Const strVerz = "f:\exc\w-w-w\tmp\rainer" ' Quellverzeichnis
Const lngZeQ = 16 ' Zeile mit Überschriften in Quelldateien
Const intSpQ = 4 ' 1. mögliche Quellspalte (Umsatz ...)
Const lngZeZ = 15 ' Zeile mit Überschriften in Zieldatei
intSpZ = 2 ' 1. Zielspalte
' Vorgaben Ende
Set wks = ActiveSheet
strFile = Dir(strVerz & "\*.xls")
If strFile = "" Then
MsgBox "Keine Dateien in '" & strVerz & "' gefunden!"
Else
While Len(strFile) > 0
Workbooks.Open Filename:=strVerz & "\" & strFile, UpdateLinks:=False
intSp = intSpQ
While Left(Cells(lngZeQ, intSp), 6) = "Umsatz"
lngLast = Cells(lngZeQ, intSp).End(xlDown).Row
Range(Cells(lngZeQ, intSp), Cells(lngLast, intSp)).Copy _
Destination:=wks.Cells(lngZeZ, intSpZ)
intSpZ = intSpZ + 1
If intSpZ > Columns.Count Then
MsgBox "Spalten der Zieldatei reichen nicht aus."
Exit Sub
End If
intSp = intSp + 1
Wend
While Not IsEmpty(Cells(lngZeQ, intSp))
If Cells(lngZeQ, intSp) = "Personalkosten" Then
lngLast = Cells(lngZeQ, intSp).End(xlDown).Row
Range(Cells(lngZeQ, intSp), Cells(lngLast, intSp)).Copy _
Destination:=wks.Cells(lngZeZ, intSpZ)
intSpZ = intSpZ + 1
If intSpZ > Columns.Count Then
MsgBox "Spalten der Zieldatei reichen nicht aus."
Exit Sub
End If
End If
intSp = intSp + 1
Wend
ActiveWorkbook.Close False
strFile = Dir
Wend
End If
End Sub