Been trying to copy-paste columns on excel VBA for days, code doesn't work no matter what
Sub CopyRangeofCellsanotherone()
Dim x As Workbook
Dim y As Workbook
Dim LastRow As Long
Dim LastRowToCopy As Long
Set x = Workbooks.Open("C:\trabalho da DELL\source.xlsx")
Set y = Workbooks.Open("C:\trabalho da DELL\destination.xlsx")
LastRowToCopy = x.Sheets("sourcesheet").Cells(x.Sheets("sourcesheet").Rows.Count, "A").End(xlUp).Row
x.Sheets("sourcesheet").Range("A" & LastRowToCopy).Copy 'copy from A1 to lastrow
LastRow = y.Sheets("destsheet").Cells(y.Sheets("destsheet").Rows.Count, "A").End(xlUp).Row 'find the last row
y.Sheets("destsheet").Range("A" & LastRow).PasteSpecial 'paste on the lastrow of destination + 1 (so next empty row)
x.Close
End Sub
I think the code is mostly self-explanatory (or atleast, what I intend it to do) but it's not working!! How can I copy contents from column A - source sheet , to column A - destination sheet? And how can I then apply that , to a set of columns? (from A to G for example). I have under 5 hours of VBA under my belt so this might look really simple to some of you... edit: forgot to mention it gives me run-time error 91 on LastRowToCopy line.
x.Sheets("sourcesheet")first. Do the same for destsheet.