Here is what I am trying to do.
I have a few spreadsheets in a folder (c:\dump\tally). I am trying to grab the data found in A3:AA3 for each of these files in the "Rollup" tab and drop them into the Excel file hosting the macro in the Sheet1 tab. And since the source data is mostly formula based, I am trying to paste the values only. Below is the code I found on this form posted by Mumps, which I've updated -
Sub CopyRange()
Application.ScreenUpdating = False
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Set wkbDest = ThisWorkbook
Dim LastRow As Long
Const strPath As String = "C:\Dump\Tally"
ChDir strPath
strExtension = Dir("*.xlsx*")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
With wkbSource
LastRow = .Sheets("Rollup").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Sheets("Rollup").Range("A3:AA3" & LastRow).Copy wkbDest.Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
.Close savechanges:=False
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True
End Sub
I am having 2 issues -
1 - data is being inserted into the same target row for each of the source files resulting in data being overwritten. I'm not very familiar with VBA but I thought it was possibly because my source data is not populating the A column when copied (by design) and because of this code "(Rows.Count, "A")" it was always seeing the row i just wrote as blank upon loop so I changed the A to B but it didn't seem to help.
2 - I am trying to get the values to paste in since the source is largely using formulas. I attempted to put the PasteSpecial Paste:=xlPasteValues parameter into the macro but I must be screwing something up there as well since I am getting errors no matter where I drop this.
Any suggestions?
I have a few spreadsheets in a folder (c:\dump\tally). I am trying to grab the data found in A3:AA3 for each of these files in the "Rollup" tab and drop them into the Excel file hosting the macro in the Sheet1 tab. And since the source data is mostly formula based, I am trying to paste the values only. Below is the code I found on this form posted by Mumps, which I've updated -
Sub CopyRange()
Application.ScreenUpdating = False
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Set wkbDest = ThisWorkbook
Dim LastRow As Long
Const strPath As String = "C:\Dump\Tally"
ChDir strPath
strExtension = Dir("*.xlsx*")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
With wkbSource
LastRow = .Sheets("Rollup").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Sheets("Rollup").Range("A3:AA3" & LastRow).Copy wkbDest.Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
.Close savechanges:=False
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True
End Sub
I am having 2 issues -
1 - data is being inserted into the same target row for each of the source files resulting in data being overwritten. I'm not very familiar with VBA but I thought it was possibly because my source data is not populating the A column when copied (by design) and because of this code "(Rows.Count, "A")" it was always seeing the row i just wrote as blank upon loop so I changed the A to B but it didn't seem to help.
2 - I am trying to get the values to paste in since the source is largely using formulas. I attempted to put the PasteSpecial Paste:=xlPasteValues parameter into the macro but I must be screwing something up there as well since I am getting errors no matter where I drop this.
Any suggestions?