I have a spreadsheet used to verify a long list of 8-digit hexadecimal numbers for duplicates.
It has two columns - one for the hexadecimal values and another where the following formula is used to check for duplicates (given that this second column is column B):
=COUNTIF($B:$B, B1)
This has worked fine for most numbers except for these values:
69000700 and 690007E2.
The first column is formatted as text, however it seems that the COUNTIF function is doing some kind of unwanted implicit cast of my hex value, and taking the second hex value as an exponent (which would make it the same as the first value).
It also doesn't seem to matter what format my hex column is - the COUNTIF function always interprets these values as numbers and therefore they appear as duplicates.
Is there a way to ensure the COUNTIF function takes these cell values as string parameters without doing an implicit cast?
Maybe it's feasible to add an extra column with a formula
=CHAR(34) & B1 & CHAR(34)
copied down.
The formula encloses the text into quotes, and "690007E2" will no longer be interpreted as "69000700" (Excel 2003).
Related
Based on this comment fom SoftTimur I did some testing on formatting and came across the following problem:
If I put =SEQUENCE(4,,-2) in A1 and custom format the range with 0;-0; it'll show the values as I intended.
If I sum the spill range in A6 using =SUM(A1#) it shows the correct value (-2).
If I put the following in B1: =TEXT(SEQUENCE(4,,-2),"0;-0;") I expected the same result as above. However Excel sees it as text (by default aligned to the left).
If I sum the spill range in B6 using =SUM(B1#) it shows the result 0 while if I sum B1+B2 I get a correct result.
Question 1: What's the explanation of the incorrect sum result in B6 versus the correct one in B7?
Question 2: Is there a different way to display a zero as blank, but keep the ability to calculate the range containing that value?
Question 1:
The TEXT function returns text and computers can't add text strings together. They can only add numbers together.
Excel will sometimes automatically perform type conversions to allow formulas to deliver what Excel guesses as being the expected result. In this case, it is sometimes turning text into numbers before adding them together. This can make like easier for users but the inconsistency can easily lead to errors.
Say A1 and A2 are formatted as text and contain the text character "1". Excel will do an implicit type conversion for operators (+-*/):
=A1 + A2
It won't do conversion for ranges in functions:
=SUM(A1:A2)
=SUM(A1,A2)
When taking in a range, the SUM function will ignore all text, so that it can still sum the numbers in the range without throwing an error. If all cells in the range contain text it will return 0.
However if you tried to use the addition operator on two cells containing text that can't be converted to numbers, it will throw an error.
Note that when you put "A1 + A2" inside the SUM function, excel first evaluates the addition operation (as this is a single input within the function which must be evaluated first), so it converts A1 and A2 to numbers at this point to create a single numeric result, and then the SUM function takes just the single numeric value as input and returns it again as the total.
If you use SUM with two separate inputs, as =SUM(A1,A2), it doesn't convert either input to a number first.
Question 2:
To get the correct result using the SUM function over the range, you can modify the original sequence formula so that it is delivering numeric values. This can be done in various ways:
1 - Convert the text back to a number by multiplying by 1 (forcing another implicit type conversion), handling the error generated for the nullstring which can't be converted to a number:
=IFERROR(TEXT(SEQUENCE(4,,-2),"0;-0;")*1,"")
2 - Test for 0 using an IF statement and return the null string:
=IF(SEQUENCE(4,,-2)<>0,SEQUENCE(4,,-2),"")
3 - Invert the sequence twice, which throws an error only when it is equal to 0:
=IFERROR(1/(1/SEQUENCE(4,,-2)),"")
OR you can modify the SUM formula to convert the range to numbers on input:
=SUM(IFERROR(B1#*1,0))
However this approach requires you to modify all formulas that look at the original sequence. If the original sequence is intended to be used as numbers (as it is in this case), it is better to have it be generated as numbers in the first place.
Example:
I am using the formula:
=IMDIV(F3,0.7)
f3 value = 37.44, so the result on the formula cell = 53.9948890...
I need to turn the 53.9948890... into a dollar value, so I want to show it like $53.99
AT THE END I JUST WANT THE DOLLAR VALUE WITHOUT ANY FORMULAS.
How can I format the results of the formula into dollar value?
I tried to highlight the cells and change the formatting but it DIDN'T WORK.
I tried to copy and paste just the numerical values and then formatting the cells, and it DIDN'T WORK.
If I type the number and then I try formatting the cell, then IT WORKS, but then I need to do it manually for hundreds of lines..
You can use DOLLAR but this returns text again which means you cannot input this into mathematical comparisons/functions as is.
=DOLLAR(IMDIV(F3,0.7))
I would recommend using ROUND instead to convert your output to be numeric and then just format the column as currency. Then you have numeric outputs that you can actually feed into functions or compare
=ROUND(IMDIV(F3,0.7),2)
The real question is why are you using IMDIV in the first place? As you have discovered, that method will require some downstream work to format to number/currency. Since you are just supplying real numbers, you don't really use the 'special sauce' that is added to the IMDIV function. You are just taking extra steps to do a standard division.
i.e. (37.44 + 0i) / (0.7 + 0i) = 37.44/0.7 so why not just use F3/.7?
As you can see in below photo, both outputs return the same number. The only difference is the IMDIV function returns this value as string which has to be converted before later use.
I am attempting to add three cells which I have formatted as hh:mm:ss
and it is giving me incorrect sum as one of them is missing hh
A B c
01:01:01 :01:01 01:01:01 SUM(A,B,C)
is returning 2:02:02 when it should be 2:03:03
I have several cells missing the HH so it is throwing off all my formulas, any way I can force the 00:01:01, on a cell that is :01:01?
Try,
=SUMPRODUCT(TIMEVALUE(RIGHT("00:00"&TEXT(A2:C2, "[hh]:mm:ss;#"), 8)))
The format mask used by the TEXT function (hh:mm:ss;#) converts real time values to text-that-looks-like-time and leaves values that are already text-that-looks-like-time unchanged. Leading zeroes and a colon are concatenated onto the result as a prefix and the right-most eight characters are parsed off with the RIGHT function. This should cover both :00:00 and :00 text values. This allows the TIMEVALUE function to process the resulting text to a true time value. The SUMPRODUCT wrapper produces cyclic calculation so that you don't have to sum three largely redundant formulas.
In the following sample image, note the default left alignment of B2 indicating text while A2 and C2 are right aligned indicating a true number, date or time.
If the values will always be contiguous as you show, you can try:
=SUMPRODUCT(--("00"&A1:C1))
Prepending "00" and the double unary will have no affect on the real time values, but will convert the "missing hour" value to a real time
I have two tables, table1 and table2. I execute VLOOKUP function in order to fill in 3 columns from table2 into table1.
For some reason, the formula doesn't work for the first row, and doesn't find the exact match from table2 even though it exists.
I made sure that both columns (for comparison) have the same format (General) and there is no extra spacing. Same conditions also apply for the rest of the records, and it works there properly.
table1 - you can see the missing matches for the first row.
table2 - you can see the match does exist, but it is not reflected in table1.
Is there any other reason why VLOOKUP can't find a match for a specific record?
Try directly evaluating equality for the two cells that you believe are equal, for instance if A2 is the value you are looking up and Sheet2!A100 is the value you think should match try this in a cell:
=(A2=Sheet2!A100)
If that returns false then you know that there is some formatting issue or error in your vlookup.
Also try Formulas / Evaluate Formula ribbon command to step through your vlookup in case that highlights something wrong.
Okay - Here's a doozy of a use-case. VLOOKUP and INDEX-MATCH were returning #N/A for values that were "apparently" equal. Cleaned my data with =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," "))) and that didn't work.
Then, I compared two cells that looked like they had matching values and they evaluated to FALSE (A1=B1 resulted in FALSE).
Then, as a last resort, I code checked each ASCII value for each character in the two cells and I found that the "-" in one cell was different from the "-" in the other cell. The first cell has the ASCII value 63 and the second cell had the ASCII value 45 for what looked like was the same "-". Turns out that 63 is a "short dash" and 45 is your standard dash or minus symbol.
The way to evaluate the ASCII codes for each character in a string is to combine the CODE function with the MID or RIGHT functions after testing the cells for length using the LEN function.
Examples:
LEN(A1) should equal LEN(B1)
For the first character in each cell:
CODE(A1) Code defaults to the first character on the left
CODE(MID(A1,2,1) yields the ASCII for the second character
CODE(MID(A1,3,1) yields the ASCII for the second character
and so on
If you have a lot of characters you can post an integer sequence next to your CODE-MID function and point the position argument to the related integer and just copy down or across
Or
You can look for the weird non-numeric character and just test that one for both cells.
Have observed scenarios like this where direct comparison fails (e.g. formula =A1=B1 resulted in FALSE) and yet length =LEN(A1)=LEN(B1) and letter by letter ASCI comparison (=CODE(A1,1,1), =CODE(A1,2,1), =CODE(A1,3,1), etc.) shows no difference.
What worked was to adjust the format of the lookup value inside the VLOOKUP.
e.g.
=VLOOKUP(A1, ARRAY, COL_NUM, FALSE) -> =VLOOKUP(TEXT(A1, "000"), ARRAY, COL_NUM, FALSE)
Here's an issue I encountered: my VLOOKUP formula returns the correct value (1) if I type in the value-to-look-up (1.016) directly in the formula, shown in cell F54.
However, if I referenced a value in column A as the value-to-look-up, the formula returned #N/A, as shown in cell F55.
(I was actually trying to VLOOKUP the current row's A value plus 0.015, i.e. VLOOKUP(A54+0.015, $A$3:$B$203, 2, FALSE))
Yet if I use the ROUND function, then the VLOOKUP formula works, as shown in F56.
I recently encountered the same issue and resolved it by changing the vlookup formula to =VLOOKUP([value to lookup], [lookup table], [column to return in the lookup table], False). Setting the last input argument to "false" forces Excel vlookup function to perform an exact match.
I have an excel formula that is producing a lot of decimal places and I cannot reduce them using the format cell -> numbers -> decimal places options. Here is the formula.
Cell named V01_MIN
V01_MIN =MIN(6:6)
Has a value of 2
Cell named V01_MAX
V01_MAX =MAX(6:6)
Has a value of 1800
Cell named V01_A
V01_A =1-V01_MIN*V01_B
Has a value of 0.889877642
Cell named V01_B
V01_B =99/(V01_MAX-V01_MIN)
Has a value of 0.055061179
X6=723
X7=V01_A+V01_B*X6 (value of 40.69911012)
X8=1
X9=X7*X8 (value of 40.69911012)
X10=1
X11=X9*X10 (value of 40.69911012)
X13==CONCATENATE(X12,", ",X11)
The final results of X13 are:
V01, 1162, 40.6991101223582
I want them to be:
V01, 1162, 40.7
I'm trying to figure out how to make this happen. I've already tried changing the cell formatting on all of these cells (including the final cell) to one decimal palce and that didn't work.
Cell formatting and the actual number in the cell are two different things.
The cell formatting merely changes how the number is shown to you in the cell.
The actual number in the cell will still keep all precision of the number.
If you wish to have the last number rounded, consider this:
X13=CONCATENATE(X12,", ",ROUND(X11,1))
This will round the result in X11 to 1 decimal place before concatenating.
By concatenating you are changing your data to text instead of a number and the number formats won't effect it. Generally you have two options
Either round within you concatenate function
X13==CONCATENATE(X12,", ",roound(X11,1))
or change it back to a number (easiest way is multiply by 1): Note this won't work in your case since you are joining text strings and variables but is useful to be aware of.
X13==CONCATENATE(X12,", ",X11)*1
and then you can format based on decimal places.