Goal: To take each row of source data with sequence number on one sheet and copy it to every other row on another sheet. When loop meets a row where the sequence number is the same as the previous row, the row should be copied directly below the previous row. When it reaches the next unique sequence number, it should leave a blank row before continuing.
What's working: I currently am using a For Step loop and a helper column in the source data. I can get my source sheet to copy to another worksheet every other row.
Problem: I don't know how to tackle the part where it pastes consecutive rows when the sequence number is the same, then starts up again with every other row. If for example the loop reaches J11 and J10 had the same sequence (001, 015, 205, etc), it copies differently.
My code can be found below, I leave a lot of comments in my code otherwise I forget in 2 months why it's working the way it does when I go to maintain it. Currently I'm not copying rows over, I'm copying 8 separate fields over which then are eventually exported as a CSV, which is why copy code might look more complicated than if they were just rows.
Public Sub CopyParcels()
'
' Copies each row of parcel data to the Import sheet
'
' Defines "i" so as to increment loop by Step size.
Dim i As Integer
For i = 0 To 500 Step 1
' Nomenclature: "Destination cells = Source Cells", copies data from DataEntry to Import
' Copy first sequence over to Import sheet
' Item Type
Sheets("Import").Cells(0 + Range("Seq1DestRow").Offset(i, 0).Value, 0 + Range("ItemDestColumn").Value) = Sheets("DataEntry").Cells(0 + i + Range("Seq1SourceRow").Value, 0 + Range("ItemSourceColumn").Value)
' Parcel ID
Sheets("Import").Cells(0 + Range("Seq1DestRow").Offset(i, 0).Value, 0 + Range("PIDDestColumn").Value) = Sheets("DataEntry").Cells(0 + i + Range("Seq1SourceRow").Value, 0 + Range("PIDSourceColumn").Value)
' Amount Due
Sheets("Import").Cells(0 + Range("Seq1DestRow").Offset(i, 0).Value, 0 + Range("AmtDueDestColumn").Value) = Sheets("DataEntry").Cells(0 + i + Range("Seq1SourceRow").Value, 0 + Range("AmtDueSourceColumn").Value)
' Payment Date, batch, and sequence
Sheets("Import").Cells(0 + Range("Seq1DestRow").Offset(i, 0).Value, 0 + Range("PmtBatSeqDestColumn").Value) = Sheets("DataEntry").Cells(0 + i + Range("Seq1SourceRow").Value, 0 + Range("PmtBatSeqSourceColumn").Value)
' Posted Date
Sheets("Import").Cells(0 + Range("Seq1DestRow").Offset(i, 0).Value, 0 + Range("PostedDateDestColumn").Value) = Sheets("DataEntry").Cells(0 + i + Range("Seq1SourceRow").Value, 0 + Range("PostedDateSourceColumn").Value)
' Null 1
Sheets("Import").Cells(0 + Range("Seq1DestRow").Offset(i, 0).Value, 0 + Range("Null1DestColumn").Value) = Sheets("DataEntry").Cells(0 + i + Range("Seq1SourceRow").Value, 0 + Range("Null1SourceColumn").Value)
' Null 2
Sheets("Import").Cells(0 + Range("Seq1DestRow").Offset(i, 0).Value, 0 + Range("Null2DestColumn").Value) = Sheets("DataEntry").Cells(0 + i + Range("Seq1SourceRow").Value, 0 + Range("Null2SourceColumn").Value)
' Null 3
Sheets("Import").Cells(0 + Range("Seq1DestRow").Offset(i, 0).Value, 0 + Range("Null3DestColumn").Value) = Sheets("DataEntry").Cells(0 + i + Range("Seq1SourceRow").Value, 0 + Range("Null3SourceColumn").Value)
Next
End Sub
Bookmarks