- Das Makro kopiert einen Teil des ersten Arbeitsblatts jeder Datei, die sich im Ordner C:\Data befindet, in das erste Arbeitsblatt Ihrer Arbeitsmappe.
- Das erste Makro macht eine normale Kopie und das zweite Makro kopiert die Werte.
Denken Sie daran, dass Excel nur 256 Spalten hat
Sub CopyColumn () Dim basebook As Workbook Dim mybook As Workbook Dim sourceRange As Range Dim destrange As Range Dim cnum As Integer Dim i As Long Dim a As Integer Application.ScreenUpdating = False With Application.FileSearch .NewSearch .LookIn = "C:\ Data". mybook.Worksheets(1).Columns("A:B") a = sourceRange.Columns.Count Set desstrange = basebook.Worksheets(1).Cells(1, cnum) sourceRange.Copy desstrange mybook.Close cnum = i * a + 1 Next i End If End With Application.ScreenUpdating = True End Sub Sub CopyColumnValues() Dim basebook As Workbook Dim mybook As Workbook Dim sourceRange As Range Dim destrange As Range Dim cnum As Integer Dim i As Long Dim a As Integer Application.ScreenUpdating = Falsch Mit Application.FileSearch .NewSearch .LookIn = "C:\Data" .SearchSubFolders = False .FileType = msoFileTypeExcelWorkbooks If .Execute() > 0 Then Set basebook = ThisWorkbook cnum = 1 For i = 1 To .FoundFiles.Count Set mybook = Workbooks.Open(.FoundFiles(i)) Set sourceRange = mybook.Worksheets( 1).Columns("A:B") a = sourceRange.Columns.Count Mit sourceRange Set desstrange = basebook.Worksheets(1).Columns(cnum). _ Resize(, .Columns.Count) End With desstrange.Value = sourceRange.Value mybook.Close cnum = i * a + 1 Next i End If End With Application.ScreenUpdating = True End Sub