How can I comment out parts of a formula in a Google Drive Spreadsheet?
In PHP you can comment a line of code using a #
what is the syntax to do the same in a Google Spreadsheet?
I want to use this to temporarily disable a part of a formula rather than write a note / comment.
For instance I have this formula:
=QUERY({
'ALPHA'!A6:X70;
'BETA'!A6:X70;
'CHARLIE'!A6:X69
},"select * where Col1 <>''
order by Col24 DESC")
I would like to be able to comment out the part:
order by Col24 DESC
Best Answer
Use the concatenation operator
&
andIF
Example
Explanation
The formula syntax doesn't include something similar to the PHP
#
comment, JavaScript//
comment,/* */
multiple line comment or HTML<!-- -->
, but you could use functions likeIF
. Another alternative isIFERROR
. If the formula returns a number,N
could be another alternative, as it returns0
when it's argument isn't a number.In this case I suggest the use of
&
andIF
because theQUERY
's second argument should be a text value.&
concatenates the two operands and returns a text value; by usingIF
we could set a condition and the value to be returned if the condition is true, in this caseorder by Col24 DESC
(please note the leading space), and another value if the condition is false, in this case I suggest to leave the second argument blank, to return a blank.You could go even further by using a cell reference for the condition to toggle the inclusion/exclusion of the order clause.
Pro-tip: Use Google Apps Script to document and toggle formulas. A cell note or comment could be used to mark those formulas that have being documented this way.