+ Reply to Thread
Results 1 to 9 of 9

Converting base 10 to base 6

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-30-2007
    Location
    London, UK
    MS-Off Ver
    Microsoft Office 2007
    Posts
    317

    Converting base 10 to base 6

    Hi Guys, is it possible to convert base 10 into base 6 without formatting a cell to "Time"?

    What I mean is say for instance Cell A2 had the start time of 9.30 instead of 9:30 and cell B2 had the end time of 10.45 instead of 10:45. Now cell C2 should subtract the end time from the start time and come up with an answer of 1:15 or even 1.15.

    I know I could do all this by formating the cells to Time Formatting but this speadsheet is for the lay person who usually enter time values using the decimal point instead of the colon.

    Any ideas?

    Thanks.
    Last edited by VBA Noob; 02-22-2008 at 12:20 PM.
    Best Regards.

    Michael
    -----------------------------------
    Windows Vista, Microsoft Office 2007

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi,Try this to start.
    Place your "from" times in Column "A" and your "to" Times in Column "B".
    Run the code, the resulting time differences will be in column "C". and a Msgbox.
    If you don't want the Msgbox, delete it from the code.

    Make sure columns "A" & "B" are formatted as numbers, and Column "C" as Time
    If you want it altered let me know
    Dim cl As Range, TT
    Dim aTl, aTr, bTl, bTr, oSa, oSb, Ts, sTr, sTl
    
    For Each cl In Range(Range("b1"), Range("b" & Rows.Count).End(xlUp))
     aTl = Split(Format(cl.Offset(0, -1), "0.00"), ".")(0)
      aTr = (Split(Format(cl.Offset(0, -1), "0.00"), ".")(1)) / 60
       bTl = Split(Format(cl.Value, "0.00"), ".")(0)
        bTr = (Split(Format(cl.Value, "0.00"), ".")(1)) / 60
         oSa = aTl + aTr
          oSb = bTl + bTr
           Ts = oSb - oSa
            sTr = Split(Format(Ts, "0.00"), ".")(0)
      If sTr < 10 Then sTr = Right(sTr, 1)
            sTl = ("." & (Split(Format(Ts, "0.00"), ".")(1))) * 60
    
             TT = sTr & ":" & sTl
              cl.Offset(0, 1).Value = TT
                MsgBox TT
    Next
    Regards Mick

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    If you want the result as 1.15, then =DOLLARFR( DOLLARDE(B2, 60) - DOLLARDE(A2, 60), 60)

    If you want 1:15, then = (DOLLARDE(B2, 60) - DOLLARDE(A2, 60) ) / 24 and format as [h]:mm
    Last edited by shg; 02-22-2008 at 01:40 PM.

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, Or better still here is a User Defined Function.
    =+DecTime("To Time","From Time")
    Open the sheet, Right click the "Tab", select "View Code". -- VB Window Appears.
    Click "Insert", "Module".
    Paste the code below, into the right hand window.
    Close VB Editor.
    Insert Function in cell, Add "To" and "From" cell references
    Click "Return"
    Function DecTime(dtF As String, dtS As String)
    Dim cl As Range, TT
    Dim aTl, aTr, bTl, bTr, oSa, oSb, Ts, sTr, sTl
    
     aTl = Split(Format(dtS, "0.00"), ".")(0)
      aTr = (Split(Format(dtS, "0.00"), ".")(1)) / 60
       bTl = Split(Format(dtF, "0.00"), ".")(0)
        bTr = (Split(Format(dtF, "0.00"), ".")(1)) / 60
         oSa = aTl + aTr
          oSb = bTl + bTr
           Ts = oSb - oSa
            sTr = Split(Format(Ts, "0.00"), ".")(0)
      If sTr < 10 Then sTr = Right(sTr, 1)
            sTl = ("." & (Split(Format(Ts, "0.00"), ".")(1))) * 60
    
             TT = sTr & ":" & sTl
              DecTime = TT
    
    End Function
    Regards Mick

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719
    Assuming your time period will be within one day try this for 1:15

    =TEXT(B2*100,"0\:00")-TEXT(A2*100,"0\:00")

    or for 1.15

    =B2-A2-0.4*(MOD(B2,1)<MOD(A2,1))

  6. #6
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    The words "Wood" and "Trees" comes to mind, but there again I've learnt something about "mso number formats"
    Mick

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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