Last active
May 24, 2018 13:36
-
-
Save chipoglesby/fcaf5828a88125bb6bdf to your computer and use it in GitHub Desktop.
Remove Extra Columns in Google Spreadsheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function removeExtraColumns() {// Formats all spreadsheets | |
| var ss = SpreadsheetApp.getActive(); | |
| for(var n in ss.getSheets()){// loop over all tabs in the spreadsheet | |
| var sheet = ss.getSheets()[n];// look at every sheet in spreadsheet | |
| var name = sheet.getName();//get name | |
| var maxColumns = sheet.getMaxColumns(); | |
| var lastColumn = sheet.getLastColumn(); | |
| var subtract = maxColumns - lastColumn; | |
| var lastNew = lastColumn + 1; | |
| if(name != "*test"&& subtract > 0){ | |
| Logger.log("Name: "+name+", Max Columns: "+maxColumns+", Last Column: "+lastColumn+", Number to Subtract: "+subtract+", The new Last Column: "+lastNew); | |
| sheet.deleteColumns(lastNew, subtract); | |
| } | |
| SpreadsheetApp.flush(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment