+ Reply to Thread
Results 1 to 18 of 18

how can i write vba code for replacing continuos fraction numbers in on row

Hybrid View

baig123 how can i write vba code for... 06-19-2014, 01:00 AM
patel45 Re: how can i write vba code... 06-19-2014, 01:44 AM
baig123 Re: how can i write vba code... 06-19-2014, 07:55 AM
jindon Re: how can i write vba code... 06-19-2014, 09:20 AM
baig123 Re: how can i write vba code... 06-20-2014, 03:06 AM
vnzerem Re: how can i write vba code... 06-19-2014, 03:32 PM
jindon Re: how can i write vba code... 06-20-2014, 03:12 AM
baig123 Re: how can i write vba code... 06-20-2014, 06:29 AM
jindon Re: how can i write vba code... 06-20-2014, 06:34 AM
baig123 i have code which replaces... 06-21-2014, 12:44 AM
protonLeah Re: i have code which... 06-21-2014, 12:52 AM
baig123 Re: i have code which... 06-21-2014, 12:58 AM
protonLeah Re: i have code which... 06-21-2014, 01:17 AM
baig123 Re: i have code which... 06-21-2014, 05:09 AM
jindon Re: i have code which... 06-21-2014, 06:17 AM
Fotis1991 Re: i have code which... 06-21-2014, 06:27 AM
baig123 Re: how can i write vba code... 06-21-2014, 06:57 AM
jindon Re: how can i write vba code... 06-21-2014, 08:04 AM
  1. #1
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    how can i write vba code for replacing continuos fraction numbers in on row

    i have attached my excelsheet Please help me out I am struck here

    i ahve continous fraction numbers in every attribute value

    how can i write vba code for replacing continuos fraction numbers in on row

    Attribute name1 Attribute Value1

    materials1 1/2 IN ID, 2/3 IN LG, 4/5 IN OD 1/4 IN THK
    materials2 1/2 IN ID, 2/3 IN LG, 4/5 IN OD
    materials3 1/2 IN ID, 2/3 IN LG


    example: 1/2 IN ID, 2/3 IN LG, 4/5 IN OD 1/4 IN THK in a single row


    i have TOOL OUT sheet

    ModelNumber Attribute Value Replace Value

    1 materials 2/4 IN LG, 3/4 IN ID, 5/9 IN OD,1/15 IN THK
    2 materials 1/2 IN LG, 2/9 IN
    3 materials 4/15 IN
    4 materials 5/18 IN
    5 materials 4/19 IN
    6 materials 2/4 IN
    7 materials 1/2 IN
    8 materials 4/15 IN
    9 materials 5/18 IN
    10 materials 4/19 IN LG, 9/8 IN
    11 materials 2/4 IN LG, 3/4 IN ID, 5/9 IN OD,1/15 IN THK

    iwant this to converted in (Replace value column)
    example 0.5 IN LG, 0.75 IN ID, 0.55 IN OD,0.06 IB THK

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: how can i write vba code for replacing continuos fraction numbers in on row

    Sub repla()
    Dim LR As Long
    Sheets("Tool_Output").Select
    LR = Range("C" & Rows.Count).End(xlUp).Row
    For r = 2 To LR
      s = Cells(r, 3)
      arr = Split(s, ",")
      For i = LBound(arr) To UBound(arr)
        p = InStr(arr(i), " IN")
        frac = Left(arr(i), p - 1)
        af = Right(arr(i), Len(arr(i)) - p + 1)
        evfrac = Format(Evaluate(frac), "0.00")
        ss = ss & evfrac & af & ", "
      Next
      Cells(r, 4) = Left(ss, Len(ss) - 2)
      ss = ""
    Next
    
    End Sub
    If solved remember to mark Thread as solved

  3. #3
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Re: how can i write vba code for replacing continuos fraction numbers in on row

    i just want that 1/2 should display .5 IN LG other values should display maximum 3 or 2 values(1/7--> .143,1/4 as .25)


    but i some doubt that if there is 1/2 -->0.50 1/7-->0.143

    i want this should be display in this format -->(1/2)---->.5 and 1/7-->.143
    followed 1/4-->.25
    Fraction Decimal
    15/16 .937
    7/8 .875
    13/16 .812
    3/4 .75
    11/16 .687
    5/8 .625
    9/16 .562
    1/2 .5
    7/16 .437
    3/8 .375
    11/32 .343
    5/16 .312
    9/32 .281
    1/4 .25
    15/64 .234
    7/32 .218
    13/64 .203
    3/16 .187
    23/128 .179
    11/64 .171
    21/128 .164
    5/32 .156
    19/128 .148
    9/64 .140
    1/8 .125
    7/64 .109
    3/32 .093
    5/64 .078
    1/16 .062
    3/64 .046
    1/32 .031
    1/64 .015

    now it showin like this

    .500 IN HD, .500 IN HUB, .071 IN OD, .125 IN THK
    .500 IN HD
    .200 IN THK
    .143 IN ID

    i want this type it should display how can i do it

    .5 IN HD, .5 IN HUB, .071 IN OD, .125 IN THK
    .5 IN HD
    .2 IN THK
    .143 IN ID
    Last edited by baig123; 06-19-2014 at 08:17 AM. Reason: paragraph

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: how can i write vba code for replacing continuos fraction numbers in on row

    Do you want it like this?
    Last edited by jindon; 06-20-2014 at 07:51 AM.

  5. #5
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Re: how can i write vba code for replacing continuos fraction numbers in on row

    its working what i am saying that

    if where value like this 1/2 it should (.5 HD or LG Or THK or OD or ID any thing it maybe)
    2/4 it should (.5 HD or LG Or THK or OD or ID any thing it maybe)
    9/2 it should (4.2 HD or LG Or THK or OD or ID or any thing it maybe)

    it should display maximum 3 values i this fraction value
    if where value like this 9/13 it should (.692 HD or LG Or THK or OD or ID any thing it maybe)
    etc

  6. #6
    Forum Contributor
    Join Date
    10-01-2013
    Location
    Houston
    MS-Off Ver
    Excel 2010
    Posts
    136

    Re: how can i write vba code for replacing continuos fraction numbers in on row

    Very Neat work Jindon...thanks for sharing your knowlegde

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: how can i write vba code for replacing continuos fraction numbers in on row

    Change the pattern
                    .Pattern = "(\d+/\d+)( IN *(LG|OD)?,?)"
    to
                    .Pattern = "(\d+/\d+)([^,]+,?)"

    vnzerem

    Thanks

  8. #8
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Re: how can i write vba code for replacing continuos fraction numbers in on row

    i am very Sorry for that its working fine
    how can modify this because in my sheet i having different fraction numbers(1/2,1-1/2,3-4/15,4-1/16) like

    example
    it should display like this ('-' relate as '/') fractions
    fraction decimal

    1-1/2 IN LG,1/2 IN MM 1.5 IN LG,0.5 IN MM
    1/2 IN OD,2-3/4 IN OD 0.5 IN LG,2.75 IN OD
    2-3/4 IN ID,1/2 IN LG 2.75 IN ID,0.5 IN LG
    -
    -
    etc

    Sub repla()
    Dim LR As Long
    Sheets("Tool_Output").Select
    LR = Range("C" & Rows.Count).End(xlUp).Row
    For r = 2 To LR
      s = Cells(r, 3)
      arr = Split(s, ",")
      For i = LBound(arr) To UBound(arr)
        p = InStr(arr(i), " IN")
        frac = Left(arr(i), p - 1)
        af = Right(arr(i), Len(arr(i)) - p + 1)
        evfrac = Format(Evaluate(frac), "0.###")
        ss = ss & evfrac & af & ", "
      Next
      Cells(r, 4) = Left(ss, Len(ss) - 2)
      ss = ""
    Next
    
    End Sub
    Last edited by baig123; 06-20-2014 at 08:36 AM. Reason: paragraph

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: how can i write vba code for replacing continuos fraction numbers in on row

    baig123

    Do you have any words for appreciation when you get the help in India?

  10. #10
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    i have code which replaces fraction to decimal but i have some issues in that

    Please help me out

    i have code which replaces fraction to decimal but i have some issues in that i my having different fractions like this code is converting fractions but diffferent fractions like(1-2/4,2-1/2,3-1/15)

    15/16 IN LG, 1-1/16 IN OD, 11/32 IN THK,21/128 IN ID
    19/128 IN LG, 2-3/64 IN OD, 1/2 IN THK, 5/64 IN ID

    this type of fractions like(1-1/16,2-3/64....etc) it is converting

    example;;after converting 1/16 it should convert 1/0.062-->16.129

    Sub repla()
    Dim LR As Long
    Sheets("Tool_Output").Select
    LR = Range("C" & Rows.Count).End(xlUp).Row
    For r = 2 To LR
      s = Cells(r, 3)
      arr = Split(s, ",")
      For i = LBound(arr) To UBound(arr)
        p = InStr(arr(i), " IN")
        frac = Left(arr(i), p - 1)
        af = Right(arr(i), Len(arr(i)) - p + 1)
        evfrac = Format(Evaluate(frac), "0.###")
        ss = ss & evfrac & af & ", "
      Next
      Cells(r, 4) = Left(ss, Len(ss) - 2)
      ss = ""
    Next
    
    End Sub

  11. #11
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,926

    Re: i have code which replaces fraction to decimal but i have some issues in that

    To attach a Workbook
    (please do not post pictures of worksheets)
    • Click Advanced (next to quick post),
    • Scroll down until you see "Manage Attachments",
    • Click that then select "add files" (top right corner).
    • Click "Select Files" find your file, click "open" click "upload"
    • Once the upload is completed the file name will appear below the input boxes in this window.
    • Click "Done" at bottom right to close the Attachment Manager.
    • Click "Submit Reply"
    Ben Van Johnson

  12. #12
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Re: i have code which replaces fraction to decimal but i have some issues in that

    attched my excel sheet

    see tool-output there sheet

    run macros there if i click the replay it converts(fraction to decimal) in the replace value

  13. #13
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,926

    Re: i have code which replaces fraction to decimal but i have some issues in that

    Sub repla()
        Dim LR As Long
        Dim Dash As Long, _
            Whole As Double
        
        Sheets("Tool_Output").Select
        LR = Range("C" & Rows.Count).End(xlUp).Row
        For r = 2 To LR
          s = Cells(r, 3)
          arr = Split(s, ",")
          For i = LBound(arr) To UBound(arr)
            Whole = 0
            p = InStr(arr(i), " IN")
            frac = Left(arr(i), p - 1)
            Dash = InStr(frac, "-")
            If Dash > 0 Then
                Whole = Left(frac, Dash - 1)
                frac = Mid(frac, Dash + 1, Len(frac))
            End If
            af = Right(arr(i), Len(arr(i)) - p + 1)
            evfrac = Whole + Format(Evaluate(frac), "0.###")
            ss = ss & evfrac & af & ", "
          Next i
          Cells(r, 4) = Left(ss, Len(ss) - 2)
          ss = ""
        Next r
    
    End Sub

  14. #14
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Re: i have code which replaces fraction to decimal but i have some issues in that

    its working Thanks



    but some doubts that if the value 1-1/16 ----> 2.063
    2-3/64 --->2.0467
    its taking round fiigure but i dont need of round figure
    how can i do it
    1-1/16 --->1.062
    2-1/16 --->2.062
    2-3/64 --->2.046
    Last edited by baig123; 06-21-2014 at 05:09 AM. Reason: paragraph

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: i have code which replaces fraction to decimal but i have some issues in that


  16. #16
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: i have code which replaces fraction to decimal but i have some issues in that

    No appriciation for the people that try to help you...

    I'll merge these 2 threads as you have replies to both of them but next time that you'll do it9duplicate threads) you'll be a banned user.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  17. #17
    Forum Contributor
    Join Date
    03-01-2014
    Location
    Mysore
    MS-Off Ver
    Excel 2007
    Posts
    379

    Re: how can i write vba code for replacing continuos fraction numbers in on row

    i am very sorry for that

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: how can i write vba code for replacing continuos fraction numbers in on row


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replacing Fraction to decimal it is not converting
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-17-2014, 03:16 AM
  2. i need an replacing fraction to decimal conversion in vba excel
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2014, 06:04 AM
  3. [SOLVED] Number Format to whole numbers, or if fraction, allow one decimal
    By chulho in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-12-2013, 05:42 PM
  4. macro to fill out a column with continuos numbers
    By lab in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-16-2009, 04:08 PM
  5. Replies: 3
    Last Post: 01-24-2005, 01:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1