|
-
Mar 1st, 2005, 09:57 AM
#1
Thread Starter
New Member
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.
-
Mar 1st, 2005, 10:10 AM
#2
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
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...
-
Mar 1st, 2005, 03:59 PM
#3
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|