web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Running a excel script
Power Automate
Unanswered

Running a excel script

(0) ShareShare
ReportReport
Posted on by 69

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

 

Categories:
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 77 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 68

#3
Expiscornovus Profile Picture

Expiscornovus 56 Most Valuable Professional

Last 30 days Overall leaderboard