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 Automate
Unanswered

Update Excel Rows

(1) ShareShare
ReportReport
Posted on by 90

Hi all,

I am new to PAD. Please help me update the Excel sheet. For example, the sheet contains employee names and employee numbers. The correct format for employee numbers should be 'ID93434343', where it starts with 'ID9' followed by a 7-digit number. Some rows are correct, but others do not start with 'ID9' or 'ID'. Please guide me on how to resolve this issue.

DN1_0-1720025842267.png

 

I have the same question (0)
  • Verified answer
    NathanAlvares24 Profile Picture
    1,714 Moderator on at

    Hi @DN1 !

     

    Please try out this flow.

    NathanAlvares24_0-1720027945744.png

    NathanAlvares24_1-1720027957728.png

    Output:

    Before:

    NathanAlvares24_2-1720028038449.png

     

    After:

    NathanAlvares24_3-1720028050403.png

     

    Code (just copy paste into your flow):

    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Users\\Username\\Desktop\\EmpDetails.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
    Excel.ReadFromExcel.ReadAllCells Instance: ExcelInstance ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
    SET nCounter TO 2
    LOOP FOREACH CurrentItem IN ExcelData
     IF (NotStartsWith(CurrentItem[1], 'ID9', True) AND CurrentItem[1].Length = 7) = $'''True''' THEN
     Text.Pad Text: CurrentItem[1] PadPosition: Text.PadPosition.Left PaddingText: $'''ID9''' TotalLength: 10 PaddedText=> PaddedText
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: PaddedText Column: $'''B''' Row: nCounter
     Variables.IncreaseVariable Value: nCounter IncrementValue: 1
     ELSE IF CurrentItem[1].Length = 8 THEN
     Text.Pad Text: CurrentItem[1] PadPosition: Text.PadPosition.Left PaddingText: $'''ID''' TotalLength: 10 PaddedText=> PaddedText
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance Value: PaddedText Column: $'''B''' Row: nCounter
     Variables.IncreaseVariable Value: nCounter IncrementValue: 1
     ELSE
     Variables.IncreaseVariable Value: nCounter IncrementValue: 1
     END
    END
    Excel.CloseExcel.CloseAndSave Instance: ExcelInstance

     

    I hope this helps.

  • Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @DN1 

     

    Please follow the below approach:

     

    Please modify excel path as per your file and folder name.

    1. **Launch Excel**:
    - Launch and open the Excel file `C:\\Boot\\EmpDetails (1).xlsx` with visibility enabled.

    2. **Read Excel Data**:
    - Read all cells from the Excel file into a data table, using the first row as headers.

    3. **Initialize Counter**:
    - Set a counter variable to `0` for tracking row indices.

    4. **Loop Through Data Table**:
    - Loop through each row in the data table.

    5. **Modify Employee Number (7 characters)**:
    - If the employee number is 7 characters long and does not start with "ID", prepend "ID9".

    6. **Modify Employee Number (8 characters)**:
    - If the employee number is 8 characters long and does not start with "ID", prepend "ID".

    7. **Increment Counter**:
    - Increment the counter variable at the end of each loop iteration.

    8. **Launch New Excel Instance**:
    - Launch a new Excel instance with visibility enabled.

    9. **Write Modified Data**:
    - Write the modified data table to the new Excel instance, including column headers.

    10. **Save Updated Excel**:
    - Save the updated Excel file as `C:\\Boot\\UpdatedExcel.xlsx`.

     

    Deenuji_0-1720027803643.png

     

    Code:

    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Boot\\EmpDetails (1).xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
    Excel.ReadFromExcel.ReadAllCells Instance: ExcelInstance ReadAsText: False FirstLineIsHeader: True RangeValue=> EmployeeExcel
    SET Counter TO 0
    LOOP FOREACH CurrentEmployee IN EmployeeExcel
     IF (NotStartsWith(CurrentEmployee['Employee Number'], $'''ID''', True) AND CurrentEmployee['Employee Number'].Length = 7) = True THEN
     Variables.ModifyDataTableItem DataTable: EmployeeExcel ColumnNameOrIndex: 1 RowIndex: Counter Value: $'''ID9%CurrentEmployee['Employee Number']%'''
     END
     IF (NotStartsWith(CurrentEmployee['Employee Number'], $'''ID''', True) AND CurrentEmployee['Employee Number'].Length = 😎 = True THEN
     Variables.ModifyDataTableItem DataTable: EmployeeExcel ColumnNameOrIndex: 1 RowIndex: Counter Value: $'''ID%CurrentEmployee['Employee Number']%'''
     END
     SET Counter TO Counter + 1
    END
    Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance1
    Excel.WriteToExcel.WriteCell Instance: ExcelInstance1 Value: EmployeeExcel.ColumnHeadersRow Column: $'''A''' Row: 0
    Excel.WriteToExcel.WriteCell Instance: ExcelInstance1 Value: EmployeeExcel Column: $'''A''' Row: 1
    Excel.SaveExcel.SaveAs Instance: ExcelInstance1 DocumentFormat: Excel.ExcelFormat.FromExtension DocumentPath: $'''C:\\Boot\\UpdatedExcel.xlsx'''

     

     

    How to copy/paste above code into your Power automate desktop flow?

    Deenuji_1-1720027869837.gif

     

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • DN1 Profile Picture
    90 on at

    Hi @NathanAlvares24 ,Thank you for your response. It is really helpful. In my folder i have multiple pdf files.  The PAD is extracting the pdf file data and writing the data into excel sheet and reads the excel sheet and manipulating the data's (adding the prefix). could you please guide me how to create a separate excel sheet for each pdf file data's and save the excel sheet based on the pdf file name which is present in the folder.

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 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard