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 / Office 365 Script - Re...
Power Automate
Answered

Office 365 Script - Replace Question

(0) ShareShare
ReportReport
Posted on by 288

Hello all.

I need some help with an Excel Online Script.  I need to go through all the cells in a column and replace special characters with nothing.  For example for every cell in the column,  I need to replace a "*" with "", and "-", with "".

 

It works fine...however when running the script in Power Automate Flow it times out.  Even without using it in Power Automate it is slow...so I'm wondering is there a way to filter the column and only provide the cells that have a special character in them?

 

Give me all the cells that have a "*" or "-" and that way I only have to update those cells...or can I do some kind of BULK replace the entire column where there is a "*" or "-"?

 

Thanks in advance.

Mark

Categories:
I have the same question (0)
  • Yutao Huang Profile Picture
    Microsoft Employee on at

    Hello @smithmrk ,

     

    Wondering if you have tried the replaceAll API.

     

    For your case, maybe something like this:

     

    let sheet = workbook.getWorksheet("Sheet1");
    sheet.replaceAll("*", "", {completeMatch: false, matchCase: false});
    sheet.replaceAll("-", "", { completeMatch: false, matchCase: false });

     

     

    Of if you only want to do that to a single column, you can probably do something like this: sheet.getRange("A1:A20").replaceAll(...).

     

    I did a bit testing to find and replace a single character in a test workbook with 20+ worksheets. It took about 2 seconds to replace all 7k+ occurrences. It worked pretty well when running in both Excel for the web and Power Automate.

  • smithmrk Profile Picture
    288 on at

    @Yutao I apologize, I failed to mention in my original post that it is a Table, so I need to update the entire column not a range of cells in the worksheet but rather a range of cells in a column in a table.

     

    You have any thoughts or ideas on how I can update a column of cells in a table?

     

    On a side note...if there is a way to filter that column and only pull the cells in that column that have a "*" or "-" then I could just loop through those cells only and update just them instead of looping through all the cells in that column.

     

    Thanks,

    Mark 

  • Yutao Huang Profile Picture
    Microsoft Employee on at

    @smithmrk ,

     

    Yes, if you only want to update a column of cells in a table, you can probably do something like this:

     

    let range = workbook.getTable("Table1").getColumn(1).getRangeBetweenHeaderAndTotal()
    range.replaceAll("*", "", { completeMatch: false, matchCase: false });
    range.replaceAll("-", "", { completeMatch: false, matchCase: false });

     

     

    The API used here is Range.replaceAll.

     

    Please give it a try and let me know what you think!

  • smithmrk Profile Picture
    288 on at

    @Yutao Instead of replacing "*" or "-" with nothing ("")...it removes EVERYTHING in that column!

    See screen shot below:

     

    2022-11-02_11-21-42.png

     

  • Verified answer
    Yutao Huang Profile Picture
    Microsoft Employee on at

    Oh no!!! I just realized the asterisk "*" is a special character used in Find and replace. It will match any single character. Using wildcard characters in searches (microsoft.com)

     

    To match the actual "*" character, you'll have to add a tilde character "~" in front of it.

    let range = workbook.getTable("Table1").getColumn(1).getRangeBetweenHeaderAndTotal()
    range.replaceAll("~*", "", { completeMatch: false, matchCase: false });
    range.replaceAll("-", "", { completeMatch: false, matchCase: false });

     

    Sorry I should have done more testing before posing my answer. Hope you didn't lose any actual data... 😓

  • smithmrk Profile Picture
    288 on at

    BINGO!

    That worked...Thanks.

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!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 464

#2
Haque Profile Picture

Haque 416

#3
David_MA Profile Picture

David_MA 323 Super User 2026 Season 1

Last 30 days Overall leaderboard