I am trying to copy from one worksheet named "List" to five worksheets named "First Upload", "Second Upload", "Third Upload", "Fourth Upload", and "Fifth Upload". I need to copy row 2 to "First Upload" row 3 to "Second Upload", row 4 to "Third Upload" etc. then loop through to the end of the worksheet (around 20,000 rows).
I am trying to end with roughly the same amount of rows on the multiple upload sheets and I need to separate them in this way due to requirements of the system I am using.
I am using the following code and it works for the first upload but brings too many results for the rest of the worksheets(ie double for the "Second Upload", triple for the "Third Upload". The code I am using is:
Sub OffsetTrial()
Dim X As Long, LastRow As Long
Dim CopyRange As Range
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
For X = 2 To LastRow Step 5
If CopyRange Is Nothing Then
Set CopyRange = Rows(X).EntireRow
Else
Set CopyRange = Union(CopyRange, Rows(X).EntireRow)
End If
Next
If Not CopyRange Is Nothing Then
CopyRange.Copy Destination:=Sheets("First Upload").Range("A2")
End If
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
For X = 3 To LastRow Step 5
If CopyRange Is Nothing Then
Set CopyRange = Rows(X).EntireRow
Else
Set CopyRange = Union(CopyRange, Rows(X).EntireRow)
End If
Next
If Not CopyRange Is Nothing Then
CopyRange.Copy Destination:=Sheets("Second Upload").Range("A2")
End If
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
For X = 4 To LastRow Step 5
If CopyRange Is Nothing Then
Set CopyRange = Rows(X).EntireRow
Else
Set CopyRange = Union(CopyRange, Rows(X).EntireRow)
End If
Next
If Not CopyRange Is Nothing Then
CopyRange.Copy Destination:=Sheets("Third Upload").Range("A2")
End If
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
For X = 5 To LastRow Step 5
If CopyRange Is Nothing Then
Set CopyRange = Rows(X).EntireRow
Else
Set CopyRange = Union(CopyRange, Rows(X).EntireRow)
End If
Next
If Not CopyRange Is Nothing Then
CopyRange.Copy Destination:=Sheets("Fourth Upload").Range("A2")
End If
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
For X = 6 To LastRow Step 5
If CopyRange Is Nothing Then
Set CopyRange = Rows(X).EntireRow
Else
Set CopyRange = Union(CopyRange, Rows(X).EntireRow)
End If
Next
If Not CopyRange Is Nothing Then
CopyRange.Copy Destination:=Sheets("Fifth Upload").Range("A2")
End If
End Sub
I thought that, in example, in the first part For X = 2 To LastRow Step 5 would start me at row 2 and offset 5 rows then For X = 3 To LastRow Step 5 would start me at row 3 and offset 5 rows but I think I was mistaken or I can't repeat the code like this. Any help with this would be greatly appreciated. Thank you