Sub Test()
For Each cell In ActiveSheet.Range("AC2:AC" & Range("AC" & Rows.Count).End(xlUp).Row)
With ActiveSheet
Reference = .Range("AB" & cell.Row).Value
Quantity = .Range("AC" & cell.Row).Value
For i = 1 To Quantity
LR = Range("AG" & Rows.Count).End(xlUp).Row
.Range("AG" & LR + 1).Value = Reference
.Range("AH" & LR + 1).Value = Quantity
Next
End With
Next cell
End Sub