- Makrot kommer att kopiera en del av det första kalkylbladet i varje fil som finns i mappen C: \ Data till det första kalkylbladet i din arbetsbok.
- Det första makrot gör en normal kopia och det andra makroet kopierar värdena.
Sub CopyRow () Dim basebook As Workbook Dim mybook As Workbook Dim sourceRange As Range Dim destrange As Range Dim rnum As Long Dim i As Long Dim a As Long Application.ScreenUpdating = False With Application.FileSearch .NewSearch .LookIn = "C: \ Data ".SearchSubFolders = False .FileType = msoFileTypeExcelWorkbooks If .Execute ()> 0 Ställ sedan in basebook = ThisWorkbook rnum = 1 För i = 1 Till .FoundFiles.Count Set mybook = Workbooks.Open (.FoundFiles (i)) Ange sourceRange = mybook.Worksheets (1) .Rows ("3: 5") a = sourceRange.Rows.Count Set destrange = basebook.Worksheets (1) .Cells (rnum, 1) sourceRange.Copy destrange mybook.Close rnum = i * a + 1 Nästa i End If End with Application.ScreenUpdating = True End Sub Sub CopyRowValues () Dim basbok As Workbook Dim mybook As Workbook Dim sourceRange As Range Dim destrange As Range Dim rnum As Long Dim i As Long Dim a As Long application.ScreenUpdating = Falskt med Application.FileSearch .NewSearch .LookIn = "C: \ Data" .SearchSubFolders = Falskt .FileType = msoFi leTypeExcelWorkbooks If .Execute ()> 0 Sedan Ställ in basebook = ThisWorkbook rnum = 1 För i = 1 Till .FoundFiles.Count Ställ in mybook = Workbooks.Open (.FoundFiles (i)) Ställ in sourceRange = mybook.Worksheets (1) .Rader ( "3: 5") a = sourceRange.Rows.Count With sourceRange Set destrange = basebook.Worksheets (1) .Cells (rnum, 1). _ Ändra storlek (.Rows.Count, .Columns.Count) Avsluta med destrange.Value = sourceRange.Value mybook.Close rnum = i * a + 1 Nästa i Avsluta om det slutar med Application.ScreenUpdating = True End Sub