Hello,
I've been lurking for a while and have found this site extremely useful. I'm trying to change a macro I used on another project. It imports the 300+ excel files I have stored in a folder into a single spreadsheet. The only problem I'm having is getting it to compile the data horizontally (not transposed, but copied and pasted "as-is" in new columns instead of rows).
Can someone please help me with this? Here is the code as it currently stands (vertical):
Sub Consolidate()
Dim sh As Worksheet, lr As Long, fPath As String, wb As Workbook, sh2 As Worksheet, fNm As String
Dim lstRw As Long, rng As Range
Set sh = Sheets(1) 'Edit name of master sheet
fPath = "C:\temp" 'Edit directory path
If Right(fPath, 1) <> "\" Then
fPath = fPath & "\"
End If
fNm = Dir(fPath & "*.xl*")
Do
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row 'Assumes Col A will be posting reference
Set wb = Workbooks.Open(fPath & fNm)
Set sh2 = wb.Sheets(1)
lstRw = sh2.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh2.Range("A2:A" & lstRw)
rng.EntireRow.Copy sh.Range("A" & lr + 1)
wb.Close False
fNm = Dir
Loop While fNm <> ""
End Sub
Bookmarks