Working with Inches/fractions

borolo222

New Member
Joined
Aug 18, 2009
Messages
42
Hi, I have this program that reads a number of cells which have some measurements in inches with the following cell format # ??/??

so i get te following results (all numbers rounded to 1/16):

58
58 1/4
3 1/16 etc
13 3/8


when the macro reads the cell it reads it as decimal.

58
58.25
3.0625
13.375

So, the output of the program has to present me each part of the fraction in a diferent column like so

col1 col2 col3
58
58 1 4
3 1 16
13 3 8


can anyone help me with this macro?
thanks in advance.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try

Code:
Sub test()
Dim c As Range, s As String, LR As Long, X
LR = Range("A" & Rows.Count).End(xlUp).Row
For Each c In Range("A1:A" & LR)
    With c
        s = WorksheetFunction.Text(.Value, "# ??/??")
        X = Split(Replace(s, "  ", "/"), "/")
        With .Offset(, 1).Resize(, UBound(X) + 1)
            .NumberFormat = "General"
            .Value = X
            .Value = .Value
        End With
    End With
Next c
End Sub
 
Upvote 0
VoG
I ran into trouble when i have a value like 3 15/16. Since it doesn't have the two spaces after the first digits it doesn't replace it with the /.


Try

Code:
Sub test()
Dim c As Range, s As String, LR As Long, X
LR = Range("A" & Rows.Count).End(xlUp).Row
For Each c In Range("A1:A" & LR)
    With c
        s = WorksheetFunction.Text(.Value, "# ??/??")
        X = Split(Replace(s, "  ", "/"), "/")
        With .Offset(, 1).Resize(, UBound(X) + 1)
            .NumberFormat = "General"
            .Value = X
            .Value = .Value
        End With
    End With
Next c
End Sub
 
Upvote 0
Try this

Code:
Sub test()
Dim c As Range, s As String, LR As Long, X
LR = Range("A" & Rows.Count).End(xlUp).Row
For Each c In Range("A1:A" & LR)
    With c
        s = WorksheetFunction.Trim(WorksheetFunction.Text(.Value, "# ??/??"))
        X = Split(Replace(s, " ", "/"), "/")
        With .Offset(, 1).Resize(, UBound(X) + 1)
            .NumberFormat = "General"
            .Value = X
            .Value = .Value
        End With
    End With
Next c
End Sub
 
Upvote 0
Thanks Peter. that solved the issue. I made a mess trying to fix it by myself, jajaja.

Thanks.



Try this

Code:
Sub test()
Dim c As Range, s As String, LR As Long, X
LR = Range("A" & Rows.Count).End(xlUp).Row
For Each c In Range("A1:A" & LR)
    With c
        s = WorksheetFunction.Trim(WorksheetFunction.Text(.Value, "# ??/??"))
        X = Split(Replace(s, " ", "/"), "/")
        With .Offset(, 1).Resize(, UBound(X) + 1)
            .NumberFormat = "General"
            .Value = X
            .Value = .Value
        End With
    End With
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,012
Messages
6,122,682
Members
449,091
Latest member
peppernaut

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