- De macro kopieert een deel van het eerste werkblad van elk bestand dat zich in de map C:\Data bevindt naar het eerste werkblad van uw werkmap.
- De eerste macro doet een normale kopie en de tweede macro kopieert de waarden.
Onthoud dat Excel slechts 256 kolommen heeft
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" .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 Set destrange = basebook.Worksheets(1).Cells(1, cnum) sourceRange.Copy destrange mybook.Close cnum = i * a + 1 Volgende 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 = False Met 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 Met sourceRange Stel destrange = basebook.Worksheets(1).Columns(cnum) in. _ Resize(, .Columns.Count) End With destrange.Value = sourceRange.Value mybook.Close cnum = i * a + 1 Next i End If End With Application.ScreenUpdating = True End Sub