Have formula treat value as text, not numeric - excel

I have an Excel formula reading data from a column. The data in that column is sometimes a date-like format, such as "10-11". Despite the fact that I've ensured that column is text formatted -- and all values display correctly as plain text, not reinterpreted as dates -- the formula is basically reinterpreting them as dates in the reference.
I need a way to force the formula's cell reference to interpret the cell as text. I tried TEXT(A1, "#") but it doesn't work -- it gives the numeric value of the date.

Brian Camire's answer explains why, but here's a worksheet function that will work for you. Note that you have to create that numeric array in it based on how long the longest string will be. It's an array formula, so when you first enter it you have to hit CTRL-SHIFT-ENTER, then you can click and drag it down the column.
=LEFT(A1, MATCH(FALSE, ISNUMBER(VALUE(MID(A1, {1,2,3,4,5}, 1))),0) - 1)

Short answer: When referring to number-like (or date-like) text values in a formula, don't use them in a place in the formula where Excel is expecting a number.
Long answer: Even if the source column is formatted as text and the values in the source column are truly entered as text (and not numbers, including dates), Excel may automatically convert text values to numbers (including dates) when you reference them in a formula if you use them in a place where Excel is expecting a number (or date).
For example (assuming US date formats), in a blank worksheet:
Set the format for column A to Text.
In cell A1, enter the value 10-11.
In cell B1, enter the formula =T(A1). The T() worksheet function returns the supplied value if it is text. Otherwise, it returns an empty string. The result of the formula in cell B1 should be 10-11, indicating that the value of A1 is text, not a number or date (in which case the result would be an empty string).
In cell C1, enter the formula =A1.
In cell D1, enter the formula =T(C1). The result should also be 10-11, indicating that the value of the formula in C1 is text, not a number or date. This shows that you can (sometimes) use a text value that looks like a number (or date) in a formula and have Excel treat it as text (which is what you want).
In cell E1, enter the formula =A1+0. The result will be 40827. This is the numeric value of the date October 11, 2011. This shows that you can (sometimes) use a text value that looks like a number (or date) in a formula and Excel will automatically convert it to a number (which is what you observed) if you use it in a place (like on either side of the + operator) where Excel is expecting a number.

To insert a value into a cell and have it not be auto-formatted, and just treated as text, you can enter it like this:
=("cell data")
eg:
=("+1 3456789")

When you use &"", Excel converts the results of a formula to text (like *1 would convert to numbers).
Thus, you can use this formula:
=TEXT(A1;"jj-mm")&""

If you put a single quote in front of the text in the cell, it should be represented as text on all references:
'10-11

Just add zero to the input!
I was having a similar problem where I had a list of numbers with a text prefix (like FOO-1, FOO-25, FOO-979) but I just wanted the number part (1, 25, 979) so I could run another formula off of that. I was using SUBSTITUTE to replace the text portion with blank, but my other formula using these numbers was coming up with bogus results. I ended up making my formula like this:
=SUBSTITUTE(B1:B10,"FOO-","")+0, and now the ISNUMBER is saying TRUE where before it was saying FALSE.

In my case, I have a form worksheet that is used by dealers to ad parts and have it calculate the final cost; it references a locked "products" sheet. The problem is that I had no way of controlling what they entered.
Products can be like:
101 = A true number
7-2009 = Reads as date
7-5601-RT = TEXT/NUMBER reads as both number or text (NOT SOLVED YET)
CP6072CD = reads as plain text
I have most of this figured out; the only one that isn't is the one that reads as both text/Number.
In case anyone is looking for a similar solution, i did the following:
I created three additional columns to test and display the three different cases: "NUMBER", "DATE" , "TEXT".
DATE: =NOT(ISERROR(DATEVALUE(B42)))
ISOTHER: =(ISNUMBER(--(MID(B42,ROW(INDIRECT("1:"&LEN(B42))),1))))
NUMBER: =ISNUMBER(B42)
NUMBER/TEXT: =NOT SOLVED YET
I42 = DATE
J42 = NUMBER
K42 = OTHER
L42 = TEXT
M42 = THE RESULT OF THE QUERY BELOW
=IF(AND(I42 = FALSE, J42 = FALSE, K42 = TRUE), "NUMBER", IF(AND( I42 = TRUE, J42= FALSE, K42=TRUE), "DATE", "TEXT"))
This (ABOVE) tests all the true/false results and depending on what the value turns out to be, I format each of them using:
ISNUMBER = VALUE(B42)
DATE FORMATTED AS B42*1
ELSE TEXT - AS ORIGINAL
=IF(M42 = "NUMBER", VALUE(B42), IF(M42 = "DATE", B42*1, B42))
So now I just need to figure out how to test if something is both text and number because the 7-5601-RT tests out as the same as number: "FALSE, FALSE, TRUE, TRUE"

Related

=ISNUMBER(SEARCH()) formula not working properly

Basically, im trying to search if values from column b is contained in cells on column a
I am currently using the formula
=ISNUMBER(SEARCH(B1,$A:$A))
and using it inside a conditional formatting to highlight the cells in column A that contains strings from column B. But it is not highlighting the correct cells
any advice?
Problem is that your ISNUMBER(SEARCH(…. formula is returning an array of values {FALSE;TRUE;FALSE;FALSE;...} one return for each item in within_text. You need to know if any of those items match.
So, with your formula, consider the array formula modification
=OR(ISNUMBER(SEARCH(B1,$A:$A)))
Since this is an array formula, you need to "confirm" it by holding down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula as observed in the formula bar
If you don't like to use the CSE entry method, you could use this formula which will return zero for no matches, or be non-zero for any matches:
=SUMPRODUCT(-ISNUMBER(SEARCH(B1,$A:$A)))
Excel's SEARCH function is used to find the position of one string within another string. Generally you use it like this:
=SEARCH("String A", "A Longer String Containing String A")
This will return the character index where first string starts within the second string, which in this case would be 28.
What you really need is a VLOOKUP. Since you're doing a textual search (substring), you need your range to be of text type instead of number.
You should do the following:
Add an extra column to the right of Column A and use TEXT function to convert entries to textual form:
=TEXT(A1, "#")
Now you can use VLOOKUP to perform a substring-match in this textual range. VLOOKUP supports wildcards when you do not ask it to perform an exact match (4th argument should be FALSE). Here is your formula then:
=VLOOKUP("*" & C1 & "*",$B:$B,1,FALSE)
Note that I have passed column B (textual column) as the lookup range, whereas C1 is the cell containing the text that you want to search.
This method also has the additional advantage that it returns the actual matched entry from the range so you don't have to find it manually.
Once you have your results, you can apply conditional formatting to it.
Highlight column A (or the relevant range in column A starting cell A1) with the first cell (which is A1 in this case) as the active cell, use the following formula as the conditional formatting rule:
=(SEARCH($B1,$A1)*(LEN($B1)>0))>0
The logic is to first search the given sub-string from the main string, then multiple the result by LEN($B1)>0 to exclude the result of 1 returned for blank cells in column B.
Note: Conditional Formatting works in array fashion so even though the formula only looks at values in the first row of the range, as long as you use the relative (or in some cases absolute) cell references correctly and highlight the result range correctly before setting up the rule, the rule will be applied across in the same way as for the first row of the array as demonstrated in this example.

Excel - Text Or Number Formula

I'm wondering if there's a shortcut to the following.
I have a product form that customers will fill out and I need the formula to format the part numbers they enter correctly. If it doesn't their entry doesn't match the products list.
Below are the variety of text/number/other variations...
Excel Columns/ Rows Example
101
7-2009
7-5601-RT
G-2121
5728B
PI-PIXES
I got all but the last one working with this formula:
FORMULA1
=AND(SUMPRODUCT(--ISNUMBER(--MID(B40,ROW($1:$9996),1)))<LEN(B40),MIN(FIND({0,1,2,3,4,5,6,7,8,9},B40&"0123456789"))<=LEN(B40))
I also have to keep it in .xls format.
Basically, I have one column that checks this above and it returns TRUE/FALSE.
I have another formula that checks for text:
FORMULA2:
=IF(I40=FALSE,"NUMBER", "TEXT")
The final column TESTS FOR TEXT/NUMBER.
FORMULA3:
=IF(J40 = "NUMBER", VALUE(B40), B40)
PI-PIXES is flagged as number because of the dash(hyphen).
Without any other option, I'm considering adding a third column to find TEXT with hyphens. I would then change FORMULA3 check if both if column 1 = TRUE+column 2 = TRUE and column 3 = TEXT but this is getting complicated and I'm wondering if there's a shortcut.
I think this does it:
=IF(SUBSTITUTE(B40,"-","")<>TEXT(B40,"#"),B40,IFERROR(VALUE(B40),B40))
If there are hyphens, it returns the B40 unchanged, eliminating dates. Otherwise, it handles it as a normal Value conversion with IFERROR.
This should work for older versions of Excel:
=IF(SUBSTITUTE(B40,"-","")<>TEXT(B40,"#"),B40,IF(ISERR(VALUE(B40)),B40,VALUE(B40)))
Or even this:
=IF(ISERR(FIND("-",B40)),IF(ISERR(VALUE(B40)),B40,VALUE(B40)),B40)

Excel Formula with if, then

I need to write a formula in Excel that performs the following:
If cell A1 contains the text ".png",".jpeg" then cell B1 = Image
If cell A2 contains the text ".mov",".mp4" then cell B2 = Video
And so on...
Also, is it possible to apply this validation with additional validation already applied? Like a list.
Solution
I broke the solution to parts so you won't be shocked by a long line of formula.
What I need to get it to work
Extract the suffix of a string, I've done that using the length of the string in column B and then putting it in column C.
B2=LEN(A2)
C2=IFERROR(RIGHT(A2,LEN(A2)-SEARCH(".",A2)),$J$4)
The IFERROR is in case the file doesn't contain a dot and then column C will show the message in cell $J$4.
Get the type by a so called "database" table which I've built to map which suffix belongs to which type of file
D2=IFERROR(INDEX($F$2:$G$8,MATCH(C2,$F$2:$F$8,0),2),$J$6)
I've used the INDEX and MATCH functions to fetch the data from the database.
The IFERROR in this case means - I didn't find the desired prefix in the Database table (in $F$2:$G$8)
After filling these formulas, drag down the data to the rest of the cells and you'll get the desired results.
Here's an image of my Excel file and below it you'll see the cells mapping to prevent you from guessing where is what.
Cells Mapping
Database = $F$2:$G$8
No Dot string = $J$4
Not a valid suffix string = $J$6
=IF(
OR(ISNUMBER(SEARCH(A1,".png")),ISNUMBER(SEARCH(A1,".jpeg")))
,"Image"
,IF(
OR(ISNUMBER(SEARCH(A2,".mov")),ISNUMBER(SEARCH(A2,".mp4")))
,"Video"
,"")
)
Please check for the closing brackets yourself as I just typed this off my head.
That formular should be used for cell B1

Excel 2 validation Data in a cell

I need to add Data Validation to a cell but it has 2 conditions:
- It should allow options from a List or a data in a Date Time Format.
I have already implemented the first condition... but I don't know how to add the second.
Can you please help me. Thank u in advance
Let's say B1 contains the value that you want to validate. Then the following formula formula will return true when B1 is either in the list DueDate, or when B1 is a valid date.
=OR(COUNTIF(DueDate,B1)=1,NOT(ISERROR(DATEVALUE(TEXT(B1,"mm/dd/yyyy")))))
Explanation:
COUNTIF return the number of occurrence of your input in the provided list. If it is 1, that means B1 exists in DueDate.
TEXT(B1,"dd/mm/yyyy") first converts B1 into the form of a date. Then DATEVALUE will return a number representing the date if the date is valid, otherwise it will return #VALUE! error.
Conclusion:
Apply the above formula to the cell that you want to validate, replacing B1 with the address of your corresponding cell. A drawback of this solution is that any number that can represent a date can pass the validation as well, e.g. 123. Nevertheless 123 is actually really a correct date in the world of Excel (it represents 05/02/1900), so we can do nothing about this.

Excel Call text in a cell as a factor in a formula

I have a need to count cells with a particular string of text. I have a list of each string of text to be counted.
I am forming a query using CountIf in the form:
=COUNTIF(C1:C4929,"String")
where every occurrence of 'String' is counted and output.
I would like to show the counts for each string of text in a column alongside the String. I have created a column with one string per cell.
What I would love to be able to do is call the string in the cell into the CountIf function, sort of like:
=COUNTIF(C1:C4929, "Whatever's in the column to the left of this output cell")
But I can't work it out. Am looking and will update here IMMEDIATELY if I work it out.
EDIT:
DONE!
=COUNTIF(C1:C4929,INDIRECT("RC[-1]",0))
Please try =COUNTIF(C1:C4929,"="&D1) copied down from E1, where ColumnD contains your strings.

Resources