ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Time calculations in VBA (https://www.excelbanter.com/excel-programming/316288-time-calculations-vba.html)

itsmaheshp[_7_]

Time calculations in VBA
 

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

--
itsmahesh
-----------------------------------------------------------------------
itsmaheshp's Profile: http://www.excelforum.com/member.php...fo&userid=1585
View this thread: http://www.excelforum.com/showthread.php?threadid=27689


mangesh_yadav[_182_]

Time calculations in VBA
 

why are you using CInt. Don't use that

--
mangesh_yada

-----------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...fo&userid=1047
View this thread: http://www.excelforum.com/showthread.php?threadid=27689


Bob Phillips[_6_]

Time calculations in VBA
 
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)


"mangesh_yadav" wrote in
message ...

why are you using CInt. Don't use that.


--
mangesh_yadav


------------------------------------------------------------------------
mangesh_yadav's Profile:

http://www.excelforum.com/member.php...o&userid=10470
View this thread: http://www.excelforum.com/showthread...hreadid=276891




mangesh_yadav[_186_]

Time calculations in VBA
 

Oops I missed on that one too. You need to declare the variable a
double as well. Thanks Bob

--
mangesh_yada

-----------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...fo&userid=1047
View this thread: http://www.excelforum.com/showthread.php?threadid=27689


Bob Phillips[_6_]

Time calculations in VBA
 
My pleasure.

Bob

"mangesh_yadav" wrote in
message ...

Oops I missed on that one too. You need to declare the variable as
double as well. Thanks Bob.


--
mangesh_yadav


------------------------------------------------------------------------
mangesh_yadav's Profile:

http://www.excelforum.com/member.php...o&userid=10470
View this thread: http://www.excelforum.com/showthread...hreadid=276891





All times are GMT +1. The time now is 10:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com