Ambasabi
Ambasabi

Reputation: 91

Why does the TEXT function not return any results if the amount of characters exceeds 253?

To make a long story short, I use a large Excel formula (about 3,000 characters in length) to put numerous rows of data into a format that allows me to insert directly into a database. I have to do this due to limitations at work. I am adding on to this formula, and am running into an issue where one of my new columns require varying amounts of text to be used.

If there is no text in this field, I then need the output to be NULL. If there is text, I need to print the text with single quotes surrounding it. This is the way I need it to work due to the way the data is exported into Excel from our program.

The [@[Callback Result]] below references the name of one of my columns so the formula can grow dynamically by targeting the value of that column in the current row.

Code snippet:

IF([@[Callback Result]]="",TEXT("NULL",""),TEXT("'"&[@[Callback Result]]&"'",""))

Output if the cell is blank: NULL

Output if the cell has 253 characters or less: 'Whatever text I want to type that takes up to 253 characters with single quotes surrounding it'

Output if the cell has over 253 characters: #VALUE! (caused by the formula throwing an error in the value.)

I have used this strategy for many other columns within the spreadsheet that require there to be a NULL printed if the targeted cell is blank, but I have never run into a situation where I have needed to use more than 253 characters (including spaces).

If anyone can provide any insight, I would greatly appreciate it as I can find no documentation explaining limitations of the TEXT function. I use a more simplified version of code (shown below) that does not require a NULL check, and it pulls in very large sets of text just fine by using:

"'"&[@Transcription]&"', "

I would prefer not to have to limit the amount of characters being input into the field, but will if there is no other way.

Sorry if my explanation is too lengthy. I couldn't think of a way to shorten my thoughts. Please let me know your thoughts or if I need to clarify anything below.

Upvotes: 2

Views: 181

Answers (2)

user4039065
user4039065

Reputation:

As mentioned in the comments above, you appear to be misusing the TEXT function as it was intended. Additonally, the format masks you are using do not appear to be correct.

Simple string concatenation should suffice.

=IF(LEN([@[Callback Result]]), "'"&[@[Callback Result]]&"'", "NULL")

Alternates:
=IF(LEN([@[Callback Result]]), CHAR(39)&[@[Callback Result]]&CHAR(39), "NULL")
=IF(LEN([@[Callback Result]]), CONCATENATE("'", [@[Callback Result]], "'"), "NULL")
=IF(LEN([@[Callback Result]]), CONCATENATE(CHAR(39), [@[Callback Result]], CHAR(39)), "NULL")

If this proposed solution proves inappropriate for your situation, provide some sample data together with the expected results and I will attempt to expand on this method.

Addendum:

While this particular problem seems to have been correctly addressed with the CONCATENATE function, it may be worthwhile to note that the TEXT function can be used for this purpose with the correct format mask. The @ symbol is used to represent text in a format string and both number and text can be formated with the same mask. Example:

=IF(LEN([@[Callback Result]]), TEXT([@[Callback Result]], "\'0.00\';\'@\'"), "NULL")

In the above, numbers are formatted to two decimal places and wrapped in single quotes. Text is wrapped in single quotes. While the backslash escape characters are not absolutely required to show single quotes (they are not a reserved character in a format mask), they do no harm here and I've used them to expand the functionality of this format mask to other characters that may absolutely require them. Example: official documentation on this worksheet function wrongly states that an asterisk (e.g. * or CHAR(42)) cannot be used under any circumstances. It can be used if preceded by the backslash escape character.

Caveat: While a good custom format mask can greatly improve productivity, it does not bypass the 253 character limit that was at the root of the original problem here.

Upvotes: 4

Ambasabi
Ambasabi

Reputation: 91

Well. I feel extra special. Hours of troubleshooting and I never even once stumbled upon the CONCATENATE function. I guess it would help if I knew of it in advance (still learning).

The below code works perfectly:

IF([@[Callback Result]]="",TEXT("NULL",""),CONCATENATE("'",[@[Callback Result]],"'"))

Sorry to waste anyone's time, and thank you for making me think more about why the TEXT function is not practical.

Upvotes: 2

Related Questions