-
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.
-
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
-
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.