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

Notifications

Announcements

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 406 Moderator

#3
abm abm Profile Picture

abm abm 245 Most Valuable Professional

Last 30 days Overall leaderboard