Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
Creating a button to find + replace using Macros

I want to create a button to perform a find + replace for a specific set of data in my sheet. I've had a look at other questions, but can't seem to get it to work!

This is a replica of my sheet: https://docs.google.com/spreadsheets/d/1KX4xBzIPq468WN57HKRelkCwN4sr_9Nd3v36m4jj4jI/edit#gid=0

The whole of column B is the data set I want to perform the F&R in. The values I want to use:

Find: " "
Replace "%20"

Essentially, replacing the spaces between words in column B with %20.

This, with some concatenation will then create some URLs for me.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

In your sample Spreadsheet, it seems that the cells "A2, "B2" are the values of https://www.harrods.com/en-gb/shopping/women-clothing/brands and 4 Moncler Simone Rocha, respectively. And, at the output column, the cell "C2" is the formula of =CONCATENATE($A$2,"#dcp=1&dppp=100&OrderBy=rank&Filter=ABRA%5E",B2). In this case, how about modifying the formula as follows?

From:

=CONCATENATE($A$2,"#dcp=1&dppp=100&OrderBy=rank&Filter=ABRA%5E",B2)

To:

=CONCATENATE($A$2,"#dcp=1&dppp=100&OrderBy=rank&Filter=ABRA%5E",SUBSTITUTE(B2," ","%20"))
  • By this modification, https://www.harrods.com/en-gb/shopping/women-clothing/brands#dcp=1&dppp=100&OrderBy=rank&Filter=ABRA%5E4%20Moncler%20Simone%20Rocha is obtained at the cell "C2".

If you want to achieve this using Google Apps Script, how about the following script?

Sample script:

Please copy and paste the following script to the script editor of Spreadsheet and save it. And when you want to run this script with an image button, please put an image to the Spreadsheet and assign the function name of myFunction to the button. By this, when you click the button, the script works. And, when the script is run, a single space of the values of column "B" are replaced with %20.

function myFunction() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Filter URLs");
  sheet.getRange("B2:B" + sheet.getLastRow()).createTextFinder(" ").replaceAllWith("%20");
}

Note:

  • As additional information, when you want to convert your current formula with Google Apps Script, you can also use the following script.

      function myFunction2() {
        const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Filter URLs");
        const url = sheet.getRange("A2").getValue();
        const values = sheet.getRange("B2:B" + sheet.getLastRow()).getValues().map(([b]) => [url + "#dcp=1&dppp=100&OrderBy=rank&Filter=ABRA%5E" + b.replace(/ /g,"%20")]);
        sheet.getRange(2, 4, values.length, 1).setValues(values);
      }
    
    • When this script is run, the URLs are put to the column "D". When you want to put the column "C", please modify getRange(2, 4, values.length, 1) to getRange(2, 3, values.length, 1).

References:

  • SUBSTITUTE
  • createTextFinder(findText) of Class Range
  • Class TextFinder
about 4 years ago · Juan Pablo Isaza Relatório

0

I've added a new sheet ("Filter URLs - Erik") to your sample spreadsheet. There, I deleted everything in Column C (including the header) and placed the following single formula in cell C1:

=ArrayFormula({"Output";IF(B2:B="",,$A$2&"#dcp=1&dppp=100&OrderBy=rank&Filter=ABRA%5E"&SUBSTITUTE(TRIM(B2:B)," ","%"))})

Expanding on one of @Tanaike's points, this one formula will create the header and all results for all rows without the need for dragging the formula, using scripts or using other Find/Replace methods.

about 4 years ago · Juan Pablo Isaza Relatório

0

If you're only looking to create urls, use

=ENCODEURL(B2)

instead. This will automatically convert all non url characters to it's percent encoding.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda