# Document your formulas right in the cell!

I’ve had worksheet amnesia so many times it’s not funny. I’ve learned not to make my formulas too complex or I’ll forget how they work. So now if the logic is arcane or I’m going to pass the worksheet to a client or co-worker I put documentation right in the formula. (Remember, what goes around comes around.)

If you’re creating a worksheet that is part of a large system or that has many integrated worksheets I recommend creating real documentation with data flow diagrams, etc. But, if you’ve just got a worksheet that contains some gnarly formulas, there are two things I use. The first is explanatory range names, like rngMonth. The second is putting text documentation directly in the formula. Magic you say! Watch how it’s done. If it looks useful, pass this newsletter on to someone else it can help.

Add formula descriptions right in the same cell as the formulas using the N function. The N function returns a 0 when used on text. In the following example, the formula is D1 * D2. Adding a zero which is returned by the text inside the N() function doesn’t change the result.

However, this example does show how you can get in trouble since if you move cells D1 or D2 the text description doesn’t update to reflect their new location. To prevent those types of errors, use a description like “Multiply units times price”.

This method works well for formulas with a numeric result, but it produces an error if you use it with a formula resulting in text. In the following example, the formula returns three text characters from the text in cell C7. Trying to add the zero from N() to the text result of the RIGHT() function results in an error.

Here’s how to add a description to formulas that result in text. It’s a little more complex, but it’s worth it when you need documentation. To use N() with a text formula, use IF() to test if N()returns a zero, which of course it will, and then use an IF() function to produce the null or nothing result, “”. Use an ampersand, &, to join the null and the results from the text formula.

Did you see something interesting in that screen shot? Formulas can have line breaks in them and still work. The line breaks allow you to put different segments of a formula on separate lines so they are easier to read. To put a line break in a formula, move the insertion point in the formula bar so it is at the end of a complete segment of formula, and then press Alt+Enter. To make the formula bar show multiple lines, just drag down its lower edge.
{"ft_lang_label":"__label__en","ft_lang_prob":0.86896056,"math_prob":0.7476047,"size":2494,"snap":"2019-51-2020-05","text_gpt3_token_len":546,"char_repetition_ratio":0.13453816,"word_repetition_ratio":0.013245033,"special_character_ratio":0.22012831,"punctuation_ratio":0.09615385,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97053796,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-13T13:56:18Z\",\"WARC-Record-ID\":\"<urn:uuid:c7159287-7433-411d-a560-f7eb26eec98b>\",\"Content-Length\":\"42355\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a9b431e1-ee4f-4d94-be7d-0485d7825a5e>\",\"WARC-Concurrent-To\":\"<urn:uuid:6f35359c-079d-4578-9c0a-c4e78ab86482>\",\"WARC-IP-Address\":\"37.60.247.105\",\"WARC-Target-URI\":\"https://www.criticaltosuccess.com/document-formulas-in-the-cell/\",\"WARC-Payload-Digest\":\"sha1:ETPLZ5QBYC4Z75IGCCI4RK2V46JTVYS4\",\"WARC-Block-Digest\":\"sha1:D3JIWGTWWGTU4GYQOMZLV5SZNRPFQZMS\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575540555616.2_warc_CC-MAIN-20191213122716-20191213150716-00513.warc.gz\"}"}