I have multiple spreadsheets that I need to copy column starting at “S4”, on a specifically named worksheet, and I need only the cells in that column (starting at S4 and everything below it) that contain data.
I need to copy that data and paste it into my “main” spreadsheet starting at A2 on a specific worksheet. I can do this with one spreadsheet, but the problem I’m running into I need VBA to find the last cell in column A that has a value and start pasting new data into the cell below it, etc… Otherwise, when it’s looking at the other spreadsheets, it’s just overwriting the data in my main spreadsheet.
You’ll notice the specified range of S4:S2000 – its purpose was for a single spreadsheet, which worked fine because I never had data past 2000, but I really just need it looking for cell values and grabbing those.
This is the chunk of code where I’m having the trouble. I want it to search starting at A2 (skipping the column header), look for the last cell that has a value and paste cells with values starting at S4 on the other worksheet.
On Error Resume Next
Set wbkCS = Workbooks.Open(strCutSheetFile(i))
On Error GoTo 0
If Not wbkCS Is Nothing Then
With wbkVer.Sheets("Cutsheets")
.Range(.Cells(2,1)).End(xlUp).Row = wbkCS.Worksheets("Cut Sheet").Range("S4:S2000").Value
I had to tweak yours a little because I’m working with protected files, but this worked:
Set copyRng1 = Worksheets("Cutsheets").Range("A2")
If copyRng1 = "" Then
wbkCS.Worksheets("Cut Sheet").Range("S4:S2000").Locked = False
wbkCS.Worksheets("Cut Sheet").Range("S4:S2000").Copy Destination:=wbkVer.Worksheets("Cutsheets").Range("A2")
Else
wbkCS.Worksheets("Cut Sheet").Range("S4:S2000").Copy Destination:=wbkVer.Worksheets("Cutsheets").Range("A" & wbkVer.Worksheets("Cutsheets").Range("A65536").End(xlUp).Row + 1)
End If
Here’s an example that may push you in the right direction…
Suppose I want to aggregate my data in
Sheet1using data fromS4:S2000in all other worksheets in the workbook.I check if
A2is empty and if so I paste the first lot of data.If
A2is not empty I get the next empty cell in column A and paste it there.