jamesplant77
New Member
- Joined
- Nov 13, 2015
- Messages
- 4
I have an aggregator tool that used VBA to copy 6 rows of data from a workbook, paste the data into one row in the aggregator workbook and then continue with all the files in a directory until all the files were looped. I now need to copy 6 rows of non-adjacent data, but paste this into 6 rows of data in the aggregator workbook, before continuing the process for all the files. This is the VBA that I am using:
Sub copyNonAdjacentCellData()
Dim myFile As String, path As String
Dim NextRow As Long, col As Long
path = "C:\Users\JamesPlantCloud21\Desktop\Timesheets - STH Staff\"
'C:\Users\JamesPlantCloud21\Desktop\Timesheets - STH Staff
myFile = Dir(path & "*.xlsx")
Application.ScreenUpdating = False
Do While myFile <> ""
Workbooks.Open (path & myFile)
Windows(myFile).Activate
Set copyrange = Sheets("JAN 23").Range("A9:B14,C9:K14,AQ9:AT14")
Windows("Timesheet_Aggregator_STH.xlsm").Activate
NextRow = ThisWorkbook.Sheets("STH_STAFF").Cells(Rows.Count, 1).End(xlUp).Row + 1
col = 1
For Each cell In copyrange
cell.Copy
Cells(NextRow, col).PasteSpecial xlPasteValues
col = col + 1
Next
Windows(myFile).Close SaveChanges:=False
myFile = Dir()
Loop
Range("A:O").EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
I am not an expert in VBA, but I believe it's something to do with the paste function in the code.
Would appreciate some expert assistance!!!
Sub copyNonAdjacentCellData()
Dim myFile As String, path As String
Dim NextRow As Long, col As Long
path = "C:\Users\JamesPlantCloud21\Desktop\Timesheets - STH Staff\"
'C:\Users\JamesPlantCloud21\Desktop\Timesheets - STH Staff
myFile = Dir(path & "*.xlsx")
Application.ScreenUpdating = False
Do While myFile <> ""
Workbooks.Open (path & myFile)
Windows(myFile).Activate
Set copyrange = Sheets("JAN 23").Range("A9:B14,C9:K14,AQ9:AT14")
Windows("Timesheet_Aggregator_STH.xlsm").Activate
NextRow = ThisWorkbook.Sheets("STH_STAFF").Cells(Rows.Count, 1).End(xlUp).Row + 1
col = 1
For Each cell In copyrange
cell.Copy
Cells(NextRow, col).PasteSpecial xlPasteValues
col = col + 1
Next
Windows(myFile).Close SaveChanges:=False
myFile = Dir()
Loop
Range("A:O").EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
I am not an expert in VBA, but I believe it's something to do with the paste function in the code.
Would appreciate some expert assistance!!!