I'm a green newbie to VBA (like today).
I was given this VBA code for my spreadsheet from Joe4 and I'm needing to add an addon to the code. Please look at the code and see what is wrong and why I am getting a compile error on the "Next" word (colored red) at the end.
Thank you and God bless,
Craig
I was given this VBA code for my spreadsheet from Joe4 and I'm needing to add an addon to the code. Please look at the code and see what is wrong and why I am getting a compile error on the "Next" word (colored red) at the end.
Rich (BB code):
Sub MyPopulateData()
Dim lr As Long
Dim r As Long
Dim nr As Long
Dim ct As Long
Application.ScreenUpdating = True
' Set initial value of new row to 2
nr = 2
' Find last row in column A with data
lr = Cells(Rows.Count, "A").End(xlUp).Row
' Loop through all rows in column C starting with row 2
For r = 2 To lr
' Get count from column H
ct = Cells(r, "D")
' See if value in column H is greater than 0
If ct > 0 Then
' Populate column R
Range(Cells(nr, "E"), Cells(nr + ct - 1, "E")) = Cells(r, "A")
' Increment next row counter
nr = nr + ct
' Find last row in column G with data
lr = Cells(Rows.Count, "G").End(xlUp).Row
' Get count from column J
ct = Cells(r, "J")
' See if value in column H is greater than 0
If ct > 0 Then
' Populate column K
Range(Cells(nr, "K"), Cells(nr + ct - 1, "K")) = Cells(r, "G")
' Increment next row counter
nr = nr + ct
End If
Next r
Application.ScreenUpdating = True
End Sub
Thank you and God bless,
Craig
Last edited by a moderator: