Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
Google Sheets script – replace blank spaces

I've got a script that's doing some onEdit formatting on a sheet of mine. All the rest is working well, and I wanted to include a line that deletes spaces from number values I'm importing. That last line is not working.

Any ideas what I'm missing here?

function onEdit(e) {
  var cell = e.range;
  var sh = e.source.getActiveSheet();  
  if(sh.getName() === "Trading Journal") {
    cell.setBackground('#fff');
    cell.setFontSize(10)
    cell.setFontFamily()
    cell.replace(/\s/g, "") 
}
}

https://docs.google.com/spreadsheets/d/1rkjO-ITeLdIHq-LLHfHcp6-1j1R0-giS6HGbwYdJ5Ek/edit?usp=sharing

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Did a bit of research regarding this, and it seems that .replace() is a string method and therefore may not work with numbers. Reference

But if you only need to remove whitespaces from numbers, here is a simple solution:

function rSpaces() {
    var ss =  SpreadsheetApp.getActiveSpreadsheet();
    var cell = ss.getActiveCell();
    cell.trimWhitespace();
}

You can assign this on an onEdit trigger and check this documentation for any font modifications you want to add.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!