Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>See if this will help. Because we're copying from an irregular (non-contiguous) range, it's a bit difficult to copy to another irregular range. So for that reason, the target range is "A1,B1,C1,D1,E1, etc", instead of "A1,B1,C1,E1,H1, etc". If that doesn't work for you, we'll need to try something a bit more elaborate.</p> <pre><code>Sub copyMultFiles() Dim rS As Range, rT As Range, Cel As Range Dim wBs As Workbook 'source workbook Dim wS As Worksheet 'source sheet Dim wT As Worksheet 'target sheet Dim x As Long 'counter Dim c As Long Dim arrFiles() As String 'list of source files Dim myFile As String 'source file ' change these to suit requirements Const csMyPath As String = "C:\Documents and Settings\Dave\Desktop\TestFolder\" 'source folder Const csMyFile As String = "*.xls" 'source search pattern Const csSRng As String = "$C$1,$C$10,$C$11,$C$34,$D$1" 'source range Const csTRng As String = "$A$1" 'target range Application.ScreenUpdating = False ' target sheet Set wT = ThisWorkbook.Worksheets(1) 'change to suit ' clear sheet wT.Cells.Clear 'may not want this, comment out!!! ' aquire list of files ReDim arrFiles(1 To 1) myFile = Dir$(csMyPath &amp; csMyFile, vbNormal) Do While Len(myFile) &gt; 0 arrFiles(UBound(arrFiles)) = myFile ReDim Preserve arrFiles(1 To UBound(arrFiles) + 1) myFile = Dir$ Loop ReDim Preserve arrFiles(1 To UBound(arrFiles) - 1) Set rT = wT.Range(csTRng) ' loop thru list of files For x = 1 To UBound(arrFiles) Set wBs = Workbooks.Open(csMyPath &amp; arrFiles(x), False, True) 'open wbook Set wS = wBs.Worksheets(1) 'change sheet to suit c = 0 Set rS = wS.Range(csSRng) 'copy source range to current target row For Each Cel In rS Cel.Copy rT.Offset(, c) 'next column c = c + 1 Next Cel wBs.Close False Set rT = rT.Offset(1) 'next row DoEvents Next x 'next book Erase arrFiles Application.ScreenUpdating = True End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload