I have an index match match formula. When i specifically refresh the index match match formula, it states a result of 0 withiut any decimal points or values. Just 0. So i believe this is not a floating point issue. However, when i use an IF formula which checks if it equates to 0, it comes up with a false. Why is this so? Is there a solution?
Without having the spreadsheet, it's hard to be sure.
But as others have stated already it could well be a floating point rounding issue.
Another option is that it may be a different data type altogether. Say one of the values is an integer number 0 and the other a string "0". Can look the same in the sheet, but definitely aren't the same.
It sounds like it is not a number at all so we will need to convert it to an integer for the comparison:
=IF(INT(VALUE(A1)) = 0, ... )
Related
I have column I as a calulation column and this is what I currently wrote.
and this gives me nothing.
=IF(B2<>""&D2<>"",B2*D2,IF(B2<>""&D2=""&C2<>"",B2*C2,IF(A2<>""&C2<>""&AND(B2&D2=""),A2*C2,IF(A2<>""&C2=""&D2<>""&B2="",A2*D2,A2*C2))))
The logic is if B2 and D2 are not null multiply b2*d2
if B2 is not null and D2 null then b2*c2
If B2 is null and D2 is not null then a2*d2
else a2*c2
Is any ways to make this code work?
Thank you
Alternative ways or rewriting your formula:
=IF(AND(B2<>"",D2<>""),B2*D2,IF(D2="",IF(B2<>"",B2*C2,A2*C2),IF(D2<>"",A2*D2,A2*C2)))
=IF(AND(B2<>"",D2<>""),B2*D2,IF(AND(B2="",D2=""),A2*C2,IF(D2="",B2*C2,A2*D2)))
They will make negligible difference in performance and what not. BruceWayne's answer is probably more readable in terms of following your logic and therefore easier to maintain or understand in the future. The above answers should provide the same results but are a few characters shorter in length.
And as a wacky alternative for thinking potentially outside the box:
=CHOOSE(SUM((B2<>"")*2+(D2<>""))+1,A2*C2,A2*D2,B2*C2,B2*D2)
Expanding (not just my waist size)
I had time on my hands so I was fooling around with the concept of TRUE and FALSE being equal to 1 and 0 when sent through a math operation. When I started looking at the options this reminded me of how a binary number works. Not that I have bgiven it too much thought, but I think it works because the options for each cell are binary or TRUE/FALSE. Since every possible combination was covered with a unique out come, I just had to come up with a formula that would produce unique results. In this case I just took the converting a a binary number approach. The key is TRUE = 1 after a math operation and FALSE = 0. Now going the other direction is not quite the same but as Jeeped once put it, 0 is FALSE and everything else is TRUE. so 3, -3, and 3.14 are all treated as TRUE if using the numerical values as the outcome of a logic check.
=IF(3.14,"THIS NUMBER IS TRUE","ONLY 0 IS FALSE")
So less side tracking and back on point (not sure how much I need to expand to!).
Looking at the table above, you will note in the yellow area, all possible combination for BLANK and NOT BLANK are listed. If you then assign a value to the column the same way binary numbers are (note row A) you can then start generating all the possible numbers
I started by generating the list I needed in E2:E5 for numbers that CHOOSE could work with. I assumed 0 would beat up CHOOSE and cause it to fail. I knew that FALSE+FALSE=0 and I also knew that TRUE+TRUE=2 and that both TRUE+FALSE=1 and FALSE+TRUE=1. I needed a way to distinguish the later two and I knew I needed a total of 4 results. That is when binary counting/conversion whatever you want to call it kicked in. I placed the following formula in D2 and copied down
=SUM((A2<>"")*2+(B2<>""))
Note the brackets around the logic check and
that the logic checks are sent through a math
operation before being summed.
technically speacking it is really:
=SUM((A2<>"")*2+(B2<>"")*1)
however the *1 is not needed
once I had that list generate, it was a simple +1 added to it to get into the 1 to 4 range seen in E2:E5.
Now that I had a way of generating the index number the only thing left to do was to match up the required results/formula with the right combination.
=CHOOSE(SUM((A2<>"")*2+(B2<>""))+1,"A","B","C","D")
Well I felt like I was beating a dead horse there for a bit, so if I over explained, my apologies. If there is something still missing ask for more explination.
UPDATE TID BIT
IF there were more columns to check it may be possible to adjust the choose formula by simply adding the next binary value to the column and making sure there is an appropriate number of results in the choose list. There should be 2^(# of columns to check) options
=CHOOSE(SUM((A2<>"")*4+(A2<>"")*2+(B2<>""))+1,"A","B","C","D","E","F","G","H")
Which kind of beats multiple nested IFs for brevity, but I think I finds the nested IFs easier to understand.
You should be using AND():
=IF(AND(B2<>"",D2<>""),B2*D2,IF(AND(B2<>"",D2=""),B2*C2,IF(AND(B2="",D2<>""),A2*D2,A2*C2)))
You seem to be mixing operators from other programming languages:
In Excel:
AND : binary operator : AND(TRUE, FALSE) => FALSE
& : concatenation : "Hello " & "World" => "Hello World"
I am using VBA to compare two times from a spreadsheet.
Im my example the actual value form the sheet is 23:00 in two cells. I use them for an if-statement, the values both come from two different arrays from the type Variant.
if dataArr(v1) = rowArr(v2) Then
If I debug the two values it shows the two value like this
0,958333333333333 / 0,958333333333333
They seem the same but the compare in the if-statement returns false
So I subtracted the two value to see if the result is zero.
dataArr(v1) - rowArr(v2)
In this case the result is not zero but
3,33066907387547E-16
So something is wrong with the compare or the two double values that represent the time.
The only working solution I found was to convert them to string values by
CStr(dataArr(v1)) = CStr(rowArr(v2))
which returns true as it should be.
I don't really like this solution because it is not really how it should work. I also investigated what happens to the values before they end up in the compare but I could not find any mistake . Actually all the values in the dataArr are coming from the spreadsheet (ListObject.DataBodyRange.Value) and then certain values are copied to the rowArr out of the dataArr so it really should be the same value.
Any suggestions? Thanks!
If the cells are actually formatted for time instead of a string, I would make the definition of my arrays a "Date" not a "Variant".
Then you would have all the date/time related functionality in VBA at your disposal (like DateDiff() ).
Sometimes floating point inaccuracies creep in. If you want to compare then take the Absolute Value (ABS) of the subtraction and see if it is below a tolerance level, say, 1E-7 (a millionth).
Thanks to Florent B I got a solution that works!
Florent B: To compare the equality of two dates, you need to round to the precision which is 24hrs x 60min x 60 sec
So the solution is:
If Round(dataArr(v1) * 86400) = Round(rowArr(v2) * 86400) Then
It makes perfektly sense. Thanks a lot!
I have two columns for the time in and time out of the employee, and I want to determine their lates and undertimes. But I cannot properly do it, I already can do the negative value to zero but I just want to know how to do the positive value to zero.
This is my formula =(G10-C10)*1440 then as per my column values it will show a positive value but I want the positive value become ZERO
Thanks!
You could use IF, which would be the most popular choice:
=IF(G10-C10>0,0,(G10-C10)*1440)
Could be read as, 'if the difference is greater than 0 (positive), then put 0, otherwise put the difference itself'.
Or a little less common, but simpler:
=MIN((G10-C10)*1440,0)
As an alternative to Jerry's answer, after applying your original formula, you can change the format of the cells to something like this:
"0";-0;0
The first 0 is for positive. The quotes around it make sure the zero gets displayed literally.
The second section (each section separated by a semi-colon ;) is for negative and the last one's for zero values.
The zero without quotes here means that one number should get displayed compulsorily.
Here's the output:
To make the sale to my customer I need to import numbers from a report into an Excel document. For example the number coming in will be 14.182392. The only reason for my guy not to buy the product is because he only wants to view 14.182 on the Excel sheet. Okay so the other catch is, the number CANNOT be rounded in any shape or form.
So what I need is a way to just show so much of number, WITHOUT ROUNDING.
Is this possible? Any ideas of how I could get around this would be fantastic.
Please try:
=TEXT(INT(A1)+VALUE(LEFT(MOD(A1,1),5)),"00.000")
Firstly =TRUNC is a better answer (much shorter). My version was connected with uncertainty in your requirement (it is odd!) and in the hope it might be easier to adjust if not exactly what you/your boss wanted.
TRUNC literally just truncates the decimals (no rounding!) to a length to suit (ie 3 if to show nn.182 given nn.182392 or say nn.182999).
LEFT may also be a better choice, but that depends upon knowing how large the integer part of your number is. =LEFT(A1,6) would display 14.189 given say 14.189999 in A1. However it would show 1.4189 given 1.4189999 in A1 (ie four decimal places).
The formula above combines text manipulation with number manipulation.:
INT takes just the integer value (here 14.)
MOD takes just the modulus – the residual that is not an integer after division, in this case by 1. So just the .182392 part. LEFT is then applied here in a similar way to as used above, but without needing to concern oneself with the length of the integer part of the source value (ie 14 or 1 etc does not matter).
VALUE then converts the result back into numeric format (string manipulation functions such as LEFT always return text format) so our abbreviated decimal string can then be added to our integer.
Finally, the TEXT part is for formatting but is hard or impossible to justify! About the only use is that it displays the result left-justified in the cell – perhaps a little warning that the number displayed is not the “true” value (eg it won’t SUM) because, as a result of a formula, it won’t be marked with a little green warning triangle.
The displayed values can use the TRUNC function like this,
=TRUNC(A1, 3)
But you must use A1 in any calculations to retain the precision of the raw value.
Easiest way I know:
=LEFT(A1; x)
where x = the amount of characters You want. Mind that the dot counts as a character as well.
I am having problems with the CountIf Function in Excel.
=COUNTIF(A:A,A2)
The A column consists of these items:
0107791489614255200011140926107503100513
0107791489614255200011140926107503100457
0107791489614255200011140926107503100518
0107791489614255200011140926107503100503
0107791489614255200011140926107503100519
0107791489614255200011140926107503100444
0107791489614255200011140926107503100521
0107791489614255200011140926107503100438
0107791489614255200011140926107503100449
0107791489614255200011140926107503100443
0107791489614255200011140926107503100501
0107791489614255200011140926107503100455
the formula results to 12, even though these set of strings are not really the same at all. It counts these strings as similar strings, I am thinking this is related to its string length?
What do you guys think? I appreciate your help.
+1, A good question. Not really a bug but a feature!
This is due to Excel implicitly converting the inputs to its internal numeric type and losing precision in doing so. Excel's internal numeric type is an IEEE floating point double precision number. (Although it does clever things with formatting and error propagation so it appears to get sums like 1/3 + 1/3 + 1/3 correct).
As they are so similar they all compare as mutually equal.
One remedy would be to prefix each string with ' (single quotation) which will prevent the conversion to the numeric type. Then the COUNTIF value returns 1. (At least in my version of Excel; 2013).
Preceding the strings with a single apostrophe will not remedy the situation. COUNTIF is designed to interpret data as numerical, where possible, irrespective of the datatype of the values in question. This is sometimes helpful, sometimes (as here) not.
SUMPRODUCT does not exhibit this property:
=SUMPRODUCT(0+($A$1:$A$12=A2))
will return 1, as desired.
Regards