Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

Script in Google Sheets which deletes every column that doesn't have a header

$
0
0

I'm trying to take an existing script but change it so that every column that is without a header is deleted.

function deleteColumns() {  var required = ["Name", "Position", "Salary"];  var sheet = SpreadsheetApp.getActiveSheet();  var width = sheet.getLastColumn();  var headers = sheet.getRange(1, 1, 1, width).getValues()[0];  for (var i = headers.length - 1; i >= 0; i--) {    if (required.indexOf(headers[i]) == -1) {      sheet.deleteColumn(i+1);    }  }}

I thought this might work but it doesn't

if (ISBLANK(required.indexOf(headers[i]) == -1)) {  sheet.deleteColumn(i+1);}

referenceError : ISBLANK is not defined.


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>