-1

I'm looking for a "find and replace" script for Google Sheets.

I have phone numbers on column C, which are in a ###-####### format.

I want to make a script that will replace the "-" to nothing.

Then it will be: ##########.

  • Welcome. Please add a brief description of your search/research efforts as is suggested on How to Ask. – Rubén Aug 7 at 13:33
1

Method 1: Using Find and Replace

Select C column or the range where you want to find and replace. Then CTRL+H for Windows or CMD+H on MacOs

In Find: -

In Replace: Nothing

Then click on Replace all.

Search

Method 2: Using a formula

You can also use =ARRAYFORMULA(REGEXREPLACE(C:c,"-",)) on cell D1 for example to obtain a column with phone numbers without - .

Edit

Method 3: Using Apps script

  // I need to replace more occurrences of different strings, so this is just an example..
  var ui = SpreadsheetApp.getUi();
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var range = ss.getRange("C:C1000").getValues();

  // this is a loop, to go through multiple cells that may contain the text, that needs to be replaced.
    for (var i = 0 ; i<range.length ; i++) {
        var le = range.length;
        var stri = range[i].toString().replace("-", "");
        Logger.log(stri);
  }  

  var msg = ui.alert("Replaced?");
  return msg;

Credit goes to Alex's answer on stackoverflow

  • Thanks for the edit marikamitsos, I really need to improve my editing and poor english skills haha – pjmg Aug 8 at 2:18
  • Is there more ressources about formating ? I didn't find instructions/guides except for meta.stackexchange.com/help/formatting // I'm looking for shortcuts, tips, or some templates. (I was looking at old answers until now for references) – pjmg Aug 8 at 2:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.