Time calculations in VBA

  • Thread starter Thread starter itsmaheshp
  • Start date Start date
I

itsmaheshp

guys,
i am back with one more problem.Now i got the value in terms of Hr
like (1.75 for 1.45hrs) which is of number format.
i have got a series of cells like this calculating the Hrs. sa
A1=1.75, A2=1.50 a3=2.50
now i want these cells to be accessed in VBA and add all the cells(
can do this in Excel also but i have to perform some other operatio
with the sum so i have choosen to use VBA) to get the valu
5.75(a1+a2+a3)
here is the code i have used for it.

Code
-------------------

Dim iTotHrs As Integer
iTotHrs =0
For i =1 To 3 Step 1
iTotHrs = iTotHrs + CInt(ActiveWorkbook.ActiveSheet.Cells(i, 1).Value)
' | |
' v v
' integer decimal : it will be 1.50,1.75 etc
Next

-------------------

here comes the actual probs.
is it make a difference that adding an integer with decimal value.
i am getting like 2, 2 (after rouding 1.50,1.75) which i am no
interested.
how can i solve this.
thanks & regards,
mahes
 
Also declare your variable iTotHrs as Double Not Integer.

You van use worksheet functiosn as well

Dim iTotHrs As Double
iTotHrs = WorksheetFunction.Sum(Range("A1:A3"))


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Oops I missed on that one too. You need to declare the variable a
double as well. Thanks Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top