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

How to apply formatting on specific Google Sheets and columns?

$
0
0

I have a Google Spreadsheet with many sheets. I want to apply (through code) formatting to specific columns to the sheets I specify.

I have tried this but my code applies the formatting to every sheet in my spreadsheet and its causing problems. I have a file named FormatColumns.gs Here are the contents of the file

function formatDate(){ var ss = SpreadsheetApp.getActive(); var sheet = ss.getActiveSheet();  sheet.getRange("B2:B").setNumberFormat('M/dd/yyyy');  sheet.getRange("A2:A").setNumberFormat("$#,##0;$(#,##0)"); };

How can I specify which sheets get the above formatting?

For example:

sheet.getRange("B2:B").setNumberFormat('M/dd/yyyy'); gets applied to ONLY sheet1 (or whichever sheets I specify)

and

sheet.getRange("A2:A").setNumberFormat("$#,##0;$(#,##0)"); gets applied to ONLY sheet2

I THINK I need to use Boolean logic and or use getSheetByName("Sheet1"); .....

**Here is an example page with permissions everyone should be able to use ** https://docs.google.com/spreadsheets/d/1Cn5tEJHNF07n25g0yc4d0I-9J_hLUceeeIMIyULYgAo/edit?usp=sharing

Thanks, everyone for the help, I'm learning and new.


Viewing all articles
Browse latest Browse all 9782

Trending Articles



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