Results 1 to 3 of 3

Thread: vba excel problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    1

    vba excel problem

    I am working on a previously designed spreadsheet that when designed had a slight flaw in logic. Basically when it was designed it was made to keep track of time, however the time was entered as 3.15 for 3 hours and 15 minutes and 4.55 for 4 hours and 55 minutes. This would work fine except for the fact that the vba code they wrote just added to two together to get total time. Excel however adds these as 3.15 + 4.55 and gets 7.70 instead of the wanted value of 8 hours and 10 minutes. Now there is about 2 years of wrongfully entered data I am working with so re-typing it probably isn't a valid solution. So I was trying to parse it at the dot and then subtract the front value from the total then adding the sum of minutes and adding another 1 to hour once the minutes go over .60. I however can't find how to parse an Int in vba. If I use split I can't get it to convert back to an int from a string. Any help would be greatly appreciated.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: vba excel problem

    Code:
    strTemp = cstr(format(<var of number>,"#0.00"))
    this gives you a string and you can use instr to find the "."

    Add up the hours and convert to minutes (x60)
    then add the minutes total to the converted hours
    Divide by 60 for total hours - minus off this x60 to give minutes


    Or

    cstr the value and replace the . with : then cdate to get time.
    Run top to bottom to get proper dates

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: vba excel problem

    What a problem, how about just adding all the time up and then divide by 60 for the hours. Then divide the
    remainder by 60 to get the minutes?

    After this is fixed you should format the column(s) as a time format to aviod this issue in the future.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width