Using Excel I am using a VLOOKUP where the lookup_value contains a formula that generates the string that should be searched. The formula:
=VLOOKUP(MID(A2,2,5),Sheet2!A:B,2,0)
All results come back with #N/A, yet if i substitute the MID() function with the value it generates the VLOOKUP functions fine.
Example data:
Sheet1
$#00001#
$#00002#
Sheet 2
00001 | Hello
00002 | World
The 00001 in sheet2 is actually a 1 in a cell that has been formatted as "00000" to display leading zeroes. This does not alter the raw underlying value of 1. You will need to convert the MID result to a true number with a double unary like,
=VLOOKUP(--MID(A2,2,5),Sheet2!A:B,2,0)
You cannot lookup text-that-looks-like-a-number in a column of true numbers regardless of how the true numbers are formatted for display.
Tip: Unless you manually change the cell alignment, text is left-aligned by default; numbers are right-aligned by default. This is a quick visual check that can prove the above scenario.
i agree with Jeeped's answer. however, looks like if $ was a literal, formula should actually contain
MID(A2,3,5)
as 00001 starts at position 3.
Formatting the column A in Sheet2 as Text is also a solution.
P.S. i am writing as answer since i was unable to comment on the question instead.
Related
=(Countifs(B:B;”*”;F:F;”<>*1”))
Why doesn't this work?
I want to count all the rows in the sheet, except the ones that has a number that ends with 1 in column F. It just count all the rows, even the ones in column F that ends with 1.
How do I exclude those?
edit
Some more information!
This is a sample of the data:
Could be up to 8000 rows some days. Column B always says "Independent instruction" so I'm using that as a base to count all the rows. Column F contain only numbers, or blank cells (meaning a number will be added later). I still want to count those rows as well (that's blank). It's just the rows that has a number in column F that ends with 1 that I want to exclude!
SUMPRODUCT gives a bit more flexibility for criteria that involve more than straightforward string-matching:
=SUMPRODUCT(--(LEN($B:$B)>0),--(RIGHT($F:$F,1)<>"1"))
The array formula:
{=COUNT(IF((F:F<>"")*(MOD(F:F;10)<>1);F:F))}
will count all non empty cells in the conditions of your question.
Don't forget to press Ctrl+Shift+Enter to place the formula.
Why doesn't this work?
Apart from the fact that you have transcribed it incorrectly (i.e. missing =, and smart quotes ”) the 'F' condition in quotes is a Text value, a formatting issue #BigBen has mentioned in connection with the 'B' values.
You say It just count all the rows so, syntactically corrected, your formula must be working on (a) all 'B's populated (with Text) and (b) all 'F's Numeric. As 1 and "1" are not the same, none of your entries in ColumnF will be excluded by your attempt (none end in "1", though presumably some do end in 1).
#Pspl's A works because its condition (for the 'F's) is based on MOD (applies to Number format values) and #jsheeran's A (my preference) because RIGHT is a string function that returns Text format even from a Number format value.
Put another way, with say 1 in F1, =F1="1" returns FALSE (so =F1<>"1" and =F1<>"*1" return TRUE - that would not suit you) whereas =RIGHT(F1)="1" returns TRUE (or, to suit you, RIGHT(F1)<>"1" returns FALSE).
You can try to use a combination of SUM and IF. Remember to adjust the formula to match your Excel formatting, i.e. replace commas (,) with semicolon (;).
This is an array formula (enter with Ctrl+Shift+Enter)
=SUM(IF(MOD($F$2:$F$25,10)<>1,1,0))
Result (updated with your data set):
When pasting the image into merged cells, the error looks like that:
So you need to make sure the formula is pasted into a single (not merged) cell.
Array formula for values greater than 1000:
=SUM(IF((MOD($F$2:$F$25,10)<>1)*($F$2:$F$25>1000),1,0))
Array formula for values less than 1000:
=SUM(IF((MOD($F$2:$F$25,10)<>1)*($F$2:$F$25<1000),1,0))
Example:
Having error in my formula.
How do i get it to display matched text output in column referencing on a column?
F11 to display A1 looking up output produce by formulas in rows above it that is not special character "-".
G11 to display B1 looking up output produce by formulas in rows above it that is not special character "-".
H11 to display B6 looking up output produce by formulas in rows above it that is not special character "-".
As shown in the picture below, formula below is my current input to reference column which produces error.
=INDEX(F5:F10,MATCH(A5:A10,A5:A10,0))
Based on Edit, you could use a formula like
=LOOKUP(2,1/(F5:F10=$A$5:$A$10),F5:F10)
Copy it across!
If there's going to only one entry and others as dash (-) then following can also be used.
=SUBSTITUTE(CONCATENATE(F5,F6,F7,F8,F9,F10),"-","")
Explanation for LOOKUP:
We simply compare values in formula column (F in this case) with values in Column A by using
(F5:F10=$A$5:$A$10) which produces results like TRUE;FALSE;FALSE;FALSE;FALSE
when these results are used to divide 1 then they're coerced to numbers (TRUE=1, FALSE=0) so the resultant array looks like 1,#DIV/0!;#DIV/0!;#DIV/0!;#DIV/0!.
We are looking in TRUE result which will be always equal to 1. So we are using a number larger than 1 i.e. 2 as LOOKUP uses binary search. Any large number can be used.
And then outer LOOKUP simply returns the matched item from passed array.
You can precisely see this by using Formula Evaluate option in the ribbon Formulas >> Formula Auditing >> Evaulate Formula.
I want to get a formula with COUNTIFS, like
=COUNTIF(A1:A3,"<>"&"")
such that when A1 = 2, A2 = "", A3 = empty, it returns 1.
Notes:
A2 contains an empty string, as the result of a formula. A3 is a blank cell, with no formulas in it.
The formula posted returns 2.
I tried using various numbers of double quotes. I always get 2.
I tried using &CHAR(34)&CHAR(34). I get 2.
The solution posted in How do I get countifs to select all non-blank cells in Excel? is what I tried, it returns 2 (not useful).
The formula would actually be =COUNTIFS(range1,cond1,range2,cond2), that is why I cannot use something like
=ROWS(A1:A3)-COUNTIF(A1:A3,"") or =ROWS(A1:A3)-COUNTBLANK(A1:A3) (see this).
range1 and range2 would come from expressions with INDIRECT, but that is probably not relevant.
I have worked it out with =SUMPRODUCT(--(expression1),--(ISNUMBER(A1:A3))), but I am specifically asking about the possibility of using COUNTIFS. Discrimination of number vs. text (e.g.) is not relevant at this point.
Blank vs. Empty string is the source of "troubles" (see, e.g., this).
Excel itself is somewhat ambiguous with respect to the definition of BLANK. In my example, ISBLANK(A2) returns FALSE, but COUNTBLANK(A2) returns 1.
I am not interested in a user Function.
Use a SUMPRODUCT function that counts the SIGN function of the LEN function of the cell contents.
As per your sample data, A1 has a value, A2 is a zero length string returned by a formula and A3 is truly blank.
The formula in C2 is,
=SUMPRODUCT(SIGN(LEN(A1:A3)))
I was having this exact problem, and I just found out about the "?*" wildcard which searches for any one or more characters, thus avoiding the empty string problem--genius! See Jonathan Gawrych's answer (posted right after the selected answer) here:
Excel Countif Not equal to string length of zero
Not sure if this works for the OP, since it looks like the value in A1 could need to be handled as a number not a string, but it might help anyone else who arrived here looking for a text-parsing solution.
Is using SUM instead of COUNTIFS an option? If so, I've found it to be much more flexible for filtering data sets. For example:
=SUM(IF(NOT(ISBLANK(A1:A3)),IF(NOT(ISTEXT(A1:A3)),1,0),0))
(entered as an array formula). IF(NOT(ISBLANK(x))... filters out non-blanks, then IF(NOT(ISTEXT(x))... filters out non-text. Whatever survives the filters is counted by summing 1. You can add as many filters as necessary. If you wanted to filter out only empty strings but include other text entries you could use a filter like
IF(ISTEXT(x),IF(LEN(x)>0,1,0),0)
Here are my 2 columns
A B
Spain [EMPTY]
France Euros
Spain Euros
In another cell, I would like to write a formula that would write the currency of each country. like if I have:
C1=Spain, C2=France,
I would want to have
D1=Euros, D2=Euros.
I tried it with VLOOKUP, but it gave me
C1=[Empty], C2=Euros
Thank you very much for your time
As others have commented, VLOOKUP will return the first match it finds, thats why you get [EMPTY] for Spain.
You can work around this by adding an intermediate column. Lets assume you insert a column B with formula =IF(C1="","",A1) and copy down for all used rows.
Column D is Spain, France etc
Column E is now =VLOOKUP(D1,B:C,2,0)
IF you can SORT your columns, sort by Column A then by B descending (Z-A) then use the vlookup you're trying to use. THis will put the country with a value 1st so V-Lookup will return a vale instead of empty. When empty is returned, its becuase EVERY single instance of that entry in column A has an empty value. However if the entry in A has Multiple values, it will pick the first from descending order.
So do you have situations in which a entry in column A has multiple values beyond 1 currency and a blank entry?
However this has a pitfall in that the Order now matters so if data is added to this spreadsheet a reorder must occur each time.
I'm more a VBA than formula guy but this (horrible!) array formula will return the first non blank match
in D1 put
=IF(MAX(IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0))>0,INDEX(B$1:B$6,MAX(IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0))),"no match")
and press Shift - Ctrl - Enter together
how it works
IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0)) checks that A1 matches each of A1 to A6, and correspondingly whether B1 to B6 is non-empty.
If both these conditions are TRUE then the row number of these matches is placed in an array, if FALSE the formula returns zero. so the first array id {0,0,3,0,0,0}
If the MAX of this array is not zero then the formula returns this cell position from the B column using INDEX in INDEX(B$1:B$6,MAX(IF(--(A$1:A$6=C1)*LEN(B$1:B$6)>0,ROW(A$1:A$6),0)))
Else there is "no match"
I will shoot this to a formula genius called Barry Houdini to see how much he can shorten it
Enlarged sample (including a true blank result) below
I feel like a fraud here.....don't ask me any VBA questions!
I note that use of MAX actually means that your formula (and chris' amended version) actually gives the last non-blank match. You can also do that with a non-CSE LOOKUP formula, i.e.
=LOOKUP(2,1/(B$2:B$6<>"")/(A$2:A$6=C1),B$2:B$6)
which will return #N/A if there's no match
for the text "no match" instead then, assuming formula returns text values you can use 2003 compatible
=LOOKUP("zzz",IF({1,0},"No match",LOOKUP(2,1/(B$2:B$6<>"")/(A$2:A$6=C1),B$2:B$6)))
For first non-blank match you can use INDEX/MATCH in a similar way, i.e.
=INDEX(B$2:B$6,MATCH(1,(B$2:B$6<>"")*(A$2:A$6=C1),0))
confirmed with CTRL+SHIFT+ENTER
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"