
Announcements
Hi!
Can anyone help me convert this macro into an office script I could run in power automate?
This macro repeats rows based on a quantity in column F and then adds a column (K) where it sequentially numbers the newly created rows.
I know nothing about scripts except that you can record them, but it would seem that the only way to repeat rows automatically is through a macro, and apparently you can't record the running of a macro in the script recorder.
I'd appreciate any help!
Sub LabelStep2()
' Copy Rows based on Qty in column f
Application.ScreenUpdating = False
Dim lRow As Long
Dim RepeatFactor As Variant
lRow = 1
Do While (Cells(lRow, "A") <> "")
RepeatFactor = Cells(lRow, "f")
If ((RepeatFactor > 1) And IsNumeric(RepeatFactor)) Then
Range(Cells(lRow, "A"), Cells(lRow, "o")).Copy
Range(Cells(lRow + 1, "A"), Cells(lRow + RepeatFactor - 1, "o")).Select
Selection.Insert Shift:=xlDown
lRow = lRow + RepeatFactor - 1
End If
lRow = lRow + 1
Loop
lr = Cells(rows.Count, "C").End(xlUp).Row
'Sequentially number rows based on column e
targetRng = "j2:j" & lr 'Define the Range you want to assign number
For Each rng In Range(targetRng)
rng.Offset(0, 1).Value = Application.WorksheetFunction.CountIf(Range(Split(targetRng, ":")(0) & ":" & rng.Address), rng.Value)
Next
Range("K1")="SEQ"
End Sub