How do I make Excel recognise TRUE or FALSE text as boolean values?
I have been using the INT formula to convert boolean values TRUE and FALSE into 1s and 0s. However, I have copied some data I have been given into my spreadsheet and Excel hasn't recognised the text as boolean in some cases.
The TRUE and FALSE text is aligned left and is formatted as 'General'. The INT formula doesn't recognise this as boolean. However, as soon as I click a TRUE or FALSE cell and then hit enter, the text becomes center aligned and my formula recognises it as boolean and converts it to an integer.
Is there any way I can make Excel recognise this without having to click on every cell and hit enter?
89 Answers
Excel won't recognize text "TRUE" or "FALSE" as their boolean equivalents... If you need to convert them, an IF statement will accomplish the task:
=IF(OR(A24,A24="TRUE"),TRUE,FALSE)Old question - but the following method may be handy for posterity.
Excel is recognizing the booleans as text. You can change the format to General for the entire column, but Excel won't re-evaluate the format until you click in each cell and hit Enter. An alternative is to use the text-to-columns function and e.g. use a very wide fixed width. The outcome will be the same single column, but Excel will be forced to re-evaluate the format and update all of your true and false entries to booleans.
People tend to make boolean values harder then they are. This is the best way to handle your problem in basic excel in my opinion (if you are OK with all other values then "TRUE" returning false):
=UPPER(TRIM(A1))="TRUE"In VBA :
Public Function ConvertToBoolean(InputString As String) As Variant Dim TempText As String TempText = UCase(Trim(InputString)) If TempText = "TRUE" Or TempText = "FALSE" Then ConvertToBoolean = TempText = "TRUE" Else ConvertToBoolean = InputString End If
End FunctionIt deals with white-spaces ,upper/lowercase and other values.
1As you anyway convert your logical values to number why do you want to change your data instead of adjusting your formula to accept text too: =INT(IF(ISLOGICAL(A1),A1,A1="TRUE"))
What does =TYPE(Value) show for the column of TRUE/FALSE?
I am using LibreOffice and not "true" Excel, but it recognizes even text fields properly...
Maybe you could search/replace TRUE with =TRUE?
You may have pasted data that included embedded spaces.
"true" and "false" will automatically convert to TRUE and FALSE "true " and "false " will be treated like text.
If you use the TRIM function it will evaluate the target cell's boolean value as TEXT. A2=TRUE (boolean) B2: =IF(TRIM(A2)="TRUE","Y","N") will evaluate it as "TRUE" within the function resulting as "Y".
None of these solutions worked well for me (Very long formula resulting in the text), so I got annoyed and wrote my own solution.
Public Function ConvertToBoolean(InputString As String) As Variant
Dim TempResults As Variant
If InputString = "True" Then TempResults = True
ElseIf InputString = "False" Then TempResults = False
Else TempResults = InputString
End If
ConvertToBoolean = TempResults
End FunctionThis doesn't bother with dealing with 1's and 0's, but you can wrap it around a string and get True, False, or the original string back, depending.
I just found a more practical solution to get the cells re-evaluated:
- Make sure the column is formatted as General
- Mark the column (so you don't accidentally replace something else)
- Use CTRL+F to search and replace FALSE with FALSE and then TRUE with TRUE
More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"