You should never have two functions with the same name. It's the same ambiguity as when there are two people called David nearby, and you say "David, come here". JavaScript resolves this ambiguity by always calling the function that appears later in your program; in effect it overwrites the former.
Note that the name of function parameters (Viz, UTH, etc) is internal business of a function; the outside world doesn't care how the function names its parameters or any other local variable. This does not distinguish one function from another. That is,
function addone(x) {
return 2*x;
}
is identical to
function addone(y) {
return 2*y;
}
In either case, you get back twice the number you put it; that's all that matters.
Back to your script: you have a bunch of functions with identical names. You have to given them different names, like this
function showColumnsViz() {
...
}
function showColumnsUTH() {
...
}
and so on.
Also, you have two functions with the name onOpen
. There should be one:
function onOpen(Viz) {
var menu = [{name: "Show Viz", functionName: "showColumnsViz"}, {name: "Hide Viz", functionName: "hideColumnsViz"}, {name: "Show UTH", functionName: "showColumnsUTH"}, {name: "Hide UTH", functionName: "hideColumnsUTH"}];
SpreadsheetApp.getActiveSpreadsheet().addMenu("Show/Hide Columns", menu);
}
Short answer
From the question:
edit: where trying to use an implementation of the script where the result satisfies a condition, I'm not certain but I think the sheet "views" the formula input as giving a result, albeit blank? So not a value of "0"
Instead of something like
values[i][0] > 0
you should use
values[i][0] != ''
Explanation
Part 1: Misconception about blank cells and empty strings.
Your formula doesn't return a blank, it returns a empty string ""
. A blank cell is coerced to 0 always but a empty string doesn't.
Example:
If A1 has the following formula =""
, =ISNUMBER(A1) returns FALSE but =A1+1 returns 1.
By the other hand, on Google Apps Script a blank cell value is handled as an empty string, not as 0 (zero).
Google Apps Script is based on JavaScript no on the "spreadsheet thinking" so there are several things like the default value of a blank cell that are handle in a different way than it's on Google Sheets.
Part 2: One practice for Google Apps Script troubleshooting
In case of doubts, a general practice is to create simple test functions that return the result to the log but in the case of Google Sheets you could use a custom function if you feel more comfortable with the Google Sheets UI than with the Script Editor.
To check the value that Google Apps Script got from an empty string you could use something like the following custom function:
/**
* Returns a 2D array
*
* @param {"A1"} input Cell reference string
* @customfunction
*/
function valueDataType(input){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getRange(input);
var value = range.getValue();
var output = [
['Value: ' + value],
['Data type: ' + typeof value]
];
return output;
}
Best Answer
Here is a workaround, but in means two things:
you will need to insert a new column (but you can hide the one that has the decimal points)
It will convert the numbers into strings so you will not be able to use them for calculations (but they will look right). You will still be able to do any calculations you need using the original data (in the 'hidden' column)
Assuming that the number you want to reformat it in cell A1, then in another cell (e.g. B1), insert the following formula:
=text(A1,"00")&","&right(text(A1,"00.00"),2)
You can also copy and "Paste values only" (Ctrl+Shift+V) so that you can then remove the original column (if you don't need it for calculations)