I have a figure in Excel. For example Cell A1: 241.86.
How do I check and change the last digit. For example, if it is greater or equal to 6 then replace it to 5, else remain the same. Eg: 241.86 to 241.85.
I have tried the following:
=IF(MID(A1,FIND(".",A1)+2,5)>=6,REPLACE(A3,3,2,A1-0.01),A1)
The above formula doesn't work, whenever its 241.86 or 241.84 the result will be 241.85 and 241.83. It simply minus 1 from the last digit. Any help will be appreciated.
You are trying to manipulate a number. Replace() is a text function and will not do what you describe.
If you only want to round down numbers where the second decimal is greater than 5, then try
=IF(ROUND(MOD(A1,0.1),2)>=0.06,FLOOR(A1,0.05),A1)
Related
I have the following 4 rows and I wish to find the decimal length (aka scale) of that decimal value. Do note that I'm importing all of the decimal data in Excel whose cell is formatted in a "Text" format (hence the trailing zeros even after the decimal values). And I do not want to convert it into decimal. I just need to find the scale of that decimal number.
Decimal Number
Scale (Formula?)
106.520000
2
0.080100
4
15.000010
5
265.000000
0
Been struggling for a very long time now. I'd appreciate any lead on this.
This is what I have tried,
• Formula used in cell B2
=LEN(MID(NUMBERVALUE(A2),FIND(".",A2)+1,255))
You could try:
Formula in B2:
=MAX(LEN(-A2)-LEN(INT(A2))-2,0)
Note: I use a decimal comma but it shouldnt matter for you.
Trying to figure out how to count the number of leading zeros in an excel cell. The value within the cell can be comprised of both numbers and letters or just numbers or just letters. The column is formatted as a text column.
So far I have been able to use
=MIN(FIND({1,2,3,4,5,6,7,8,9},A1&"123456789"))-1
This gets me all the leading zeros correctly for cells containing only numbers but when it is a combination of both digits and letters it also counts the letters.
eg. 00012 = 3 (correct) 000ab = 5 (should be 3)
Is there a way that I can adapt this formula to not count letters?
Try:
=SEARCH(LEFT(SUBSTITUTE(TEXT(A1,"#"),"0",""),1),A1)-1
Try looking for the first digit/character that isn't a zero and subtract 1.
=AGGREGATE(15, 7, ROW($1:$9)/(MID(A2, ROW($1:$9), 1)<>"0"), 1)-1
=IF(LEFT(A2,3)="ABC","DEF"),RIGHT(A2,LEN(A2)-3),IF(LEFT(A2,2)="GH"),RIGHT(A2,LEN(A2)-2)
As this does not work, below is what I am attempting to accomplish and an example of it.
Essentially I am trying to remove the first few letters off of a SKU #. However the amount of letters before the SKU can vary and there is letters at the end of the SKU which I do not want removed.
Example:
AB12345
CDE54321XY
Z123
With a result of:
12345
54321XY
123
My knowledge and use of VBA is almost non-existent so I have not tried to do anything with that as I believe the line I have above could work with minor tweaking though I may be wrong.
It's not as good as a regular expression, and since there are only 10 digits, it turns out not too long. The below is an array formula (entered with Ctrl+Shift+Enter):
=MID(A1,MIN(IFERROR(SEARCH({0,1,2,3,4,5,6,7,8,9},A1),9^99)),LEN(A1))
The formula will give an error (#VALUE!) if there are no numbers. It basically looks for the position of a digit in the string and finds the smallest one. For the first example, SEARCH gets the positions: #VALUE!, 3 (1 is at position 3), 4 (2 is at position 4), 5, 6, 7, #VALUE!, #VALUE!, #VALUE!, #VALUE!. The smallest being 3 (I'm using IFERROR and a big number --9^99-- so it ignores the #VALUE!), the MID will take all characters as from the 3rd character inclusive.
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.
I have 3 numbers in excel.
A1. 498
A2. 899
A3. 5209
I want the numbers as the followings:
B1. 49800
B2. 89900
B3. 52090
I am still finding the solutions via online but most of the resource is discussing about leading zeros.
Please, could you kindly give me any ideas? Thanks.
I hope this formula may be of some use:
=A1 & REPT("0"; 5 - LEN(A1))
Thought this does not set the format of the cell itself (which I doubt can be done as you are changing the value of the cell by adding the zeros)
The formula only works if you are dealing with numbers as text, so you may need to convert them to text in the formula (TEXT(A1; "0") instead of A1)
you can do this one quite easily without VBA - using an IF and the very handy REPT function:
=IF(LEN(H13)<5,H13&REPT(0,5-LEN(H13)),H13)
Essentially - if the length is less than 5 - you repeat 0 up to the amount of times that its missing.
Seems like simple math to me. Essentially you want to shift left (base 10) a certain number of times. We can do this by:
Calculate the ceiling of the base-10 logarithm of the value to get it's "length"
Subtract the result from the target "length" of 5, this is the number of places we want to shift
Take 10 to this power and multiply back by the value.
In other words, where x represents the value in column A you want to transform:
In Excel, this would be expressed as:
=A1*POWER(10,(5-CEILING(LOG10(A1),1)))