Extract fraction as a whole number

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
852
Hello
I want to extract just the fraction as a whole numer even if the fraction has a zero at its end
Example
16.1500 - 12.140 - 10.01 - 60.0060

The results should be

1500 - 140 - 01 - 0060
 
UDF?

Code:
Function YK(r As Range) As String
    Dim s As String

    s = r(1).Text
    If InStr(s, ".") Then YK = Mid(s, InStr(s, ".") + 1)
End Function

Or alternately...
Code:
Function YK(R As Range) As String
  YK = Mid(R.Text, InStr(R.Text & ".", ".") + 1)
End Function
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Fantastic Function
Wonderful solutions
Thank you very much for everybody helps me even if he helps with an idea to reach the goal.
 
Upvote 0
Just need to refresh the results in the previous function.. As the result doesn't change if I changed the input unless to double click the cell which has the formula
 
Upvote 0
Or alternately ...
Alternatively? The point of assigning a variable is to avoid reading the cell twice.
 
Upvote 0
Alternatively? The point of assigning a variable is to avoid reading the cell twice.
Point taken, although I am not sure how significant the time difference is "in human terms". I tested our functions by having a subroutine call each one 100,000 times... using your function, the subroutine took 1.53 seconds to complete the task whereas it took 2.25 seconds using my function (using my computer, of course). While your method is definitely faster, I am not sure a user would notice, let alone be inconvenienced by, the 7/10 of a second difference (7.2 microseconds per function call) while waiting for that many cells to be processed. Again, I understand your point (it is actually what I do when three or more calls to the same cell are used), but for the amount of data I am guessing such a function would probably be put to use against, I don't think my alternative is all that bad. By the way, you may find it interesting that using this version of assigning the value to YK in your function...

YK = Mid(s, InStr(s & ".", ".") + 1)

added only 1/100 of a second to the processing of those 100,000 cells.
 
Upvote 0
Just need to refresh the results in the previous function.. As the result doesn't change if I
changed the input unless to double click the cell which has the formula

Please do it for me this is the last thing to do about this thread
 
Upvote 0
Just need to refresh the results in the previous function.. As the result doesn't change if I
changed the input unless to double click the cell which has the formula
Which "previous function"? What is the message number that has the function?
 
Upvote 0
The UDF won't recalculate if you change the format of a cell, if that's what you mean, because formatting doesn't trigger calculation. Do Ctrl+Alt+F9 to recalculate all formulas.
 
Upvote 0
The UDF won't recalculate if you change the format of a cell, if that's what you mean, because formatting doesn't trigger calculation. Do Ctrl+Alt+F9 to recalculate all formulas.

Great solution..
But Can I know if there is a code that can do that within the UDF?
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,812
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top