Converting units
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 7 of 7

Thread: Converting units

  1. #1
    New Member
    Join Date
    Mar 2002
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    Greetings,
    I am trying to solve a simple problem using excel. I would like excel to convert the following numbers, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 2.10, 2.11 (in feet) into 2.0, 2.08, 2.17, 2.25, 2.33, 2.4, 2.5,2.6, 2.66,2.75,2.83,2.9, respectively. How do you think I should go about solving this problem. Can it be done with Macros with the least effort? I cannot use formulas or functions to do it since I will be dealing with multiple IF Then statements. I appreciate your help. Thank you.
    Sincerely,
    Steve

  2. #2
    MrExcel MVP Aladin Akyurek's Avatar
    Join Date
    Feb 2002
    Location
    The Hague, NL
    Posts
    81,785
    Post Thanks / Like
    Mentioned
    12 Post(s)
    Tagged
    1 Thread(s)

    Default

    On 2002-03-24 15:07, StevenData wrote:
    Greetings,
    I am trying to solve a simple problem using excel. I would like excel to convert the following numbers, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 2.10, 2.11 (in feet) into 2.0, 2.08, 2.17, 2.25, 2.33, 2.4, 2.5,2.6, 2.66,2.75,2.83,2.9, respectively. How do you think I should go about solving this problem. Can it be done with Macros with the least effort? I cannot use formulas or functions to do it since I will be dealing with multiple IF Then statements. I appreciate your help. Thank you.
    Sincerely,
    Steve
    Did you consider using the CONVERT worksheet function?

    Aladin

  3. #3
    MrExcel MVP Jay Petrulis's Avatar
    Join Date
    Mar 2002
    Location
    Chicago, IL USA
    Posts
    2,040
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-03-24 15:07, StevenData wrote:
    Greetings,
    I am trying to solve a simple problem using excel. I would like excel to convert the following numbers, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 2.10, 2.11 (in feet) into 2.0, 2.08, 2.17, 2.25, 2.33, 2.4, 2.5,2.6, 2.66,2.75,2.83,2.9, respectively. How do you think I should go about solving this problem. Can it be done with Macros with the least effort? I cannot use formulas or functions to do it since I will be dealing with multiple IF Then statements. I appreciate your help. Thank you.
    Sincerely,
    Steve
    Hi Steve,

    If I am reading you correctly, your data says 2.3, but that really means 2 feet 3 inches. 2.11 is 2 feet 11 inches, right?

    If your data is in A1:A12 try,

    =INT(A1)+IF(ISERROR(FIND(".",A1,1)),0,RIGHT(A1,LEN(A1)-FIND(".",A1,1))/12)

    and copy down the list.

    The error checking is required because the FIND call throws an error at the integers.

    HTH,
    Jay

    Edit: The above requires that your data range is text values. That way, there is a distinction between 2.1 and 2.10.

    The code from DK doesn't handle the 2.10 and 2.11 properly. It can easily be adjusted, depending on some information needed from you (see last part of message). It's quick and prefereable to using another column. Yogi's reply is incorrect for all but 2.10 and 2.11.

    Please let us know if your data is formatted so that 2.1 is clearly distinct from 2.10. This is the root cause of the troubles.

    [ This Message was edited by: Jay Petrulis on 2002-03-24 21:59 ]

  4. #4
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,936
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    If you want a macro to do this conversion on a range of cells then perhaps this will work:-

    Code:
    Sub ConvertFeetAndInches()
    Dim cl As Range
    
    For Each cl In Selection.Cells
        If IsNumeric(cl.Value) Then
            cl.Value = Format(Int(cl.Value) + (cl.Value - Int(cl.Value)) * 10 / 12, "#,##0.00")
        End If
    Next
    End Sub
    Hope it helps,
    D

  5. #5
    MrExcel MVP
    Join Date
    Mar 2002
    Location
    Michigan USA
    Posts
    11,454
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-03-24 15:07, StevenData wrote:
    Greetings,
    I am trying to solve a simple problem using excel. I would like excel to convert the following numbers, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 2.10, 2.11 (in feet) into 2.0, 2.08, 2.17, 2.25, 2.33, 2.4, 2.5,2.6, 2.66,2.75,2.83,2.9, respectively. How do you think I should go about solving this problem. Can it be done with Macros with the least effort? I cannot use formulas or functions to do it since I will be dealing with multiple IF Then statements. I appreciate your help. Thank you.
    Sincerely,
    Steve
    Hi StevenData:
    The following simple formula will do what you are looking for ...

    if your entry with 2ft and 2digit inches is in B21 then decimal feet will be ...
    =INT(B21)+RIGHT(B21,2)/12

    so here is how your numbers workout using the above formula

    2.1 2.01
    2.2 2.02
    2.3 2.03
    2.4 2.03
    2.5 2.04
    2.6 2.05
    2.7 2.06
    2.8 2.07
    2.9 2.08
    2.10 2.83
    2.11 2.92

    HTH
    Please post back if it works for you ... otherwise explain alittle further and let us take it from there.


    Regards!

    Yogi Anand, D.Eng, P.E.
    Energy Efficient Building Network LLC
    www.energyefficientbuild.com

  6. #6
    MrExcel MVP
    Join Date
    Mar 2002
    Location
    Michigan USA
    Posts
    11,454
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Jay:
    I just saw your posting ... you are right that my earlier post shows incorrect results for 2ft&in01 through 2ft&in09. I don't know why how I reported the results like that, the correct formula and the results are as follows:
    2 ft&in.00 =INT(B21)+RIGHT(B21,2)/12
    2 ft&in.01 2.08
    2 ft&in.02 2.17
    2 ft&in.03 2.25
    2 ft&in.04 2.33
    2 ft&in.05 2.42
    2 ft&in.06 2.50
    2 ft&in.07 2.58
    2 ft&in.08 2.67
    2 ft&in.09 2.75
    2 ft&in.10 2.01
    2 ft&in.11 2.92
    2 ft&in.12 3.00

    StevenData, please note that I have used two digit representation for inches -- otherwise you run into problems differentiating between 2.1 and 2.10

    Sorry for the confusion in my earlier posting!

    [ This Message was edited by: Yogi Anand on 2002-03-25 09:39 ]

  7. #7
    New Member
    Join Date
    Mar 2002
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Greetings,
    Thank you so very much for your responses to my post.
    The problem is actually more complicated and involves converting feet.feet to feet.inches for a range of values from 1 to 30. For instance, 2.1 (feet.feet) is approximately equal to 2.08 (feet.inches) and 2.10 (feet.feet, that is two feet and 0.10 feet) is a equal to 2.83(feet.inches, that is two feet and 83 inches). The real dilemma among others is the fact that 2.1 and 2.10 are the same numeric values but very different measurements.
    My solution was that to isolate the decimal part of each value (in feet) and then convert them into inches by multiplying them by 10 (or 100 for .10 and .11) and then divide them by 12. The result in inchesthen can be added to their respective isolated digits. This is a small piece of code in C, but writing a macro using VB for it proved rather difficult.
    I am trying some of the solutions you have provided, especially the macro posted by dk sounds promising. Further assistance will be deeply appreciated.

    Thanks again,
    Steve

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com