madddogcom
New Member
- Joined
- Feb 7, 2014
- Messages
- 4
Trying to copy data from one sheet to another via VBA. I can get the first set of data to copy over. But when I try to do it again with other data the receiving sheet does not paste at say row 103, but row 2103! I've tried different things and none have worked.
After getting this to work right, I'll be combining 4-6 sheets similarly copying the data over then a large sort.
Where, oh where have I gone wrong?
After getting this to work right, I'll be combining 4-6 sheets similarly copying the data over then a large sort.
Where, oh where have I gone wrong?
VBA Code:
Sub CopyRowsToEnd()
'Declare variables
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim rng1 As Range
Dim rng2 As Range
Dim lastRow1 As Long
Dim lastRow2 As Long
lastRow1 = Sheets("PFIT").Cells.SpecialCells(xlCellTypeLastCell).Row
'Range("A2").Select
'Set variables to the worksheets
Set ws1 = Sheets("PFIT")
Set ws2 = Sheets("Sheet8")
'Set range to the rows to be copied
Set rng1 = ws1.Range("A2:T2" & lastRow1)
lastRow2 = Sheets("Sheet8").Cells.SpecialCells(xlCellTypeLastCell).Row
'Set range to the destination in the second sheet
Set rng2 = ws2.Range("A" & lastRow2 + 1)
'Copy the rows
rng1.copy
'Paste the rows at the end of the destination range
rng2.PasteSpecial xlPasteFormulas
End Sub