Excel Right function - excel

I have a excel sheet with cell value 0.010, 0.020 etc., I want to get the values 3 digits after the decimal ie., "010" "020" etc., If I use the Right function Right(cell,3) it returns me ".01" ".02". The reason is the Right function ignores the "0" at the end of decimal point. Is there any other function that accomplish this.

You probably first need to convert the numeric value to a string:
=RIGHT(TEXT(CELL,"0.000"),3)

Related

Excel Average - Counting the number of variables

I'm using the average function excel to get the average of a series of hotel prices in various European cities.
=average(21,42,63,84,105)
I'd like to be able to count the number of variables in each average function (for example, in the above example there's 5). The data is scrubbed from websites which is why it's in the format above rather than placed into separate cells.
Is there a way to do this without taking out the variables, putting them into a cell and then separating out the cells using Text to Columns?
Thanks!
You can turn your equation into a string using FORMULATEXT() and then deduce the number of values being averaged by counting the instances of commas in your string (which relates to your final answer by Total Commas + 1 = Total Values
The first portion of the equation counts the character length with commas. The second portion counts the character length without commas. The difference is simply the number of commas present. We then add one since your last value is not followed by a comma
=LEN(FORMULATEXT(A1))-LEN(SUBSTITUTE(FORMULATEXT(A1),",",""))+1
Assumes your average formula is in cell A1
I am a fan of using UDFs, so here's an alternate method.
You can create a custom User Defined Function (UDF) for this. Just split the function by the deliminator and get your number from the UBOUND().
Public function getNumArgs(inputRng as range) as long
'First check that you are actually looking at a formula
If Left(inputRng.Formula, 1) <> "=" Then
getNumArgs = False
exit function
End If
getnumargs = ubound(split(inputrng.formula, ",")) + 1
end function
You will add 1 because VBA uses Base 0.
You will then use your custom UDF the same way you do any other worksheet formula:
=getNumArgs(A1)
The largest benefit of using a UDF is that you do not have to remember a complex formula.

Excel formula for count numbers of decimals

I need to count the numbers of decimals places of a number.
The A1 cell value is:
123456.78.
The formula in B1 is:
=LEN(MOD(A1,1))
The results of MOD(A1,1) is:
0.78
I expected the LEN to be 4 (LEN(0.78)=4).
The Excel formula calculates 17 because the forumula returns:
0.779999999998836
Should I try a different approach? For example looking for the separator char?
=LEN(A1)-FIND(".",A1)
Try this:
=LEN(RIGHT(A1;LEN(A1)-FIND(",";A1)))
A better formula managing a non decimal entry and different decimal separators:
=IF(ISNUMBER(FIND(".";A1));LEN(A1)-FIND(".";A1);IF(ISNUMBER(FIND(",";A1));LEN(A1)-FIND(",";A1)))
I see that the Len function is causing the math function to return the incorrect value for some reason (Len(Mod(123456.78, 1)) is returning 17 not 4, whereas Len(Mod(6.78,1) correctly returns 4).
You can add the TEXT function to your formula to change it to text, with a format of "General" to preserve the decimal precision, before calculating the length: LEN(TEXT(MOD(A1,1), "General")).
For those wanting to use this to calculate the number of decimal places without the leading "0.", simply subtract 2 from the result.

Right(text;5) is not the same as a 5 character text

I have a match function that I could not get working. I boiled it down to the point that it can't find the appropriate match since the values are not the same, apparently.
I have the value 21337 in cell D59. In cell S59 I have the function: Right($d59;5), which displays 21337. However when I enter in a cell: =D59=S59 i get the return FALSE.
I use the Right() function because cells in column D contain concatenated values, where the last 5 values are of importance. For example D60 contains 21337 - 21448, where 21448 is the value I want to match.
Anyone has a clue on what might be the problem?
With no formatting you'll see that 21337 is right aligned - showing this is a number and treated as a number by Excel.
On the other hand Right($d59;5) will show the number left aligned, indicating that the returned value is being treated as text by Excel.
If you try Right($d59;5)*1 Excel will implicitly convert the value back to a number (due to the calculation performed) and both values will be equal.
To be explicit about the conversion, as Brian has pointed out, use VALUE(Right($d59;5)).
If you use "Formula" > "Evaluate Formula", does it show the penultimate Evaluation as21337="21337"
The LEFT(..) function will convert the number to a string, and the string and the number will not equate. Try either =TEXT(D59,"#")=S59 or =D59=N(Left(S59)) to convert in your comparison, or change the code in S59 to =N(Right($D59,5)) to make S59 show a number
(The N(..) function converts a string to a number, returns 0 if Not A Number)

Excel Remove Decimal Places

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.

using array formula to average if

i have some cells d1:d10. Some have numbers, others contain "". The "" is the result of an =iferror(,"") function to leave a blank cell.
I am trying to average d1:d10 but only including the cells that are not "".
I have =AVERAGE(IF(D12:D51<>"",D12:D51)) followed by ctrl+shft+enter but it is still taking the average of all the cells (essentially taking the sum and dividing by 10, where I want it to take the sum and divide by less than 10 depending on the number of "" cells)
I couldn't reproduce your problem in Excel 2013.
Normally, Excel's average function ignores text, empty cells and logical values. So, the following formula should do what you are trying to do.
=AVERAGE(D1:D10)
The if clause in your function returns either some numbers or FALSE. Again, normally, Excel's average function ignores FALSE values so it shouldn't behave like you said. If it somehow is converting boolean values to numeric values based on Excel's version (FALSE to zero) you can just give a string instead of a boolean value so it has to ignore those values:
=AVERAGE(IF(D1:D10<>"", D1:D10, "s"))
Alternatively you can calculate the average without the average function:
=SUM(IF(D1:D10<>"", D1:D10))/COUNT(IF(D1:D10<>"", D1:D10))

Resources