youngbella
New Member
- Joined
- Sep 27, 2020
- Messages
- 19
- Office Version
- 2010
- Platform
- Windows
Hi, I'm new to VBA.
I did some coding to do copy and paste but in loop.
However, the second loop is not running. is there something wrong with my code?
Basically, I have a list in "sheet2" and I want to copy and paste it to "sheet1" sheet and skipping few rows for each list.
Can someone help me??
I did some coding to do copy and paste but in loop.
However, the second loop is not running. is there something wrong with my code?
Basically, I have a list in "sheet2" and I want to copy and paste it to "sheet1" sheet and skipping few rows for each list.
Can someone help me??
VBA Code:
Sub copypasteskip()
Dim sheet1 As Variant
Dim sheet2 As Variant
Dim endnumber As Integer
Dim finalrow As Variant
Dim i As Integer
Dim r As Integer
Set sheet1 = ThisWorkbook.Worksheets("June")
Set sheet2 = ThisWorkbook.Worksheets("ImportData")
endnumber = sheet1.Cells(Rows.Count, "A").End(xlUp).Row
finalrow = sheet2.Cells(Rows.Count, "D").End(xlUp).Row
For r = 11 To endnumber 'the list should paste starts at rows 11, cells "A"
For i = 14 To finalrow 'the list need to be copy starts at rows 14,cells "D"
sheet2.Cells(i, "D").End(xlDown).Copy
sheet1.Cells(r, "A").PasteSpecial xlPasteValues
Next i
r = r + 7 'need to skips 7 rows for each list
Next r
End sub