I am trying to write a VBA Excel Macro to look through hundreds of thousands of lines of data to make sure that each unique entry in column A has a number of entries equal to column C.
For example:
Source Account Id 84512 occurs 6 times but there needs to be 12 occurrences (as indicated by column C). This means I need to add 6 lines, before (or after) the existing 6 lines.
Next we see Source Account Id 64857 occurs once but needs to occur 5 times. I would add 4 lines above and have the same Source Account Id code and the same Account Name. The rest of the cells can be "0".
Here is an example of the finished product:
Here is what I have so far:
Sub InsertRowAtChangeInValue()
Dim lRow As Long
Dim nMonths As Long
For lRow = Cells(Cells.Rows.count, "A").End(xlUp).Row To 2 Step -1
nMonths = 12 - Cells(Application.ActiveCell.Row, 3).Value
If Cells(lRow, "A") <> Cells(lRow - 1, "A") Then Rows(lRow).EntireRow.Resize(nMonths).Insert
Next lRow
End Sub
Please let me know if you have any suggestions.
*All data in these examples is fictional