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

189
Views
How to delete empty columns with header in google sheet?

Someone asked this before but not working How do I delete empty columns with the header in google sheet? I still have issues that it shows cannot delete the column but only can hide. How to make the code work?

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

0

Delete All Empty Columns

function deleteAllEmptyColumns() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet();
  const cols = sh.getLastColumn();
  let d = 0;
  [...Array.from(new Array(cols).keys())].forEach((idx => {
    if (sh.getRange(1, idx + 1 - d, sh.getLastRow()).getValues().flat().filter(e => e).length == 0) {
      sh.deleteColumn(idx + 1 - d++);//delete counter increments here
    }
  }));
  sh.deleteColumns(sh.getLastColumn() + 1, sh.getMaxColumns() - sh.getLastColumn());

}

You must remember to keep track of the columns deleted to the left of getLastColumn().

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!