I have some VBA code as this:
rrows=lastrow/4
if lastrow is 138 then rrows should be 34.5 but I always get 34(no decimal)
How do I fix that
Thanks
Don Guillett - 30 Sep 2006 16:05 GMT
I just did this and got 34.5
Sub lastrowdecimal()
lastrow = 138
rrows = lastrow / 4
MsgBox rrows
End Sub

Signature
Don Guillett
SalesAid Software
dguillett1@austin.rr.com
>I have some VBA code as this:
> rrows=lastrow/4
[quoted text clipped - 3 lines]
> How do I fix that
> Thanks
Andy Pope - 30 Sep 2006 16:05 GMT
Hi,
What type of variable is rrows declared as?
If you have used Long or Integer then the decimal information will not
be stored.
Cheers
Andy
> I have some VBA code as this:
> rrows=lastrow/4
>
> if lastrow is 138 then rrows should be 34.5 but I always get 34(no decimal)
> How do I fix that
> Thanks

Signature
Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
pcor - 30 Sep 2006 16:46 GMT
That did it....Thanks
Ian M
> Hi,
>
[quoted text clipped - 11 lines]
> > How do I fix that
> > Thanks
Gord Dibben - 30 Sep 2006 17:01 GMT
Sub test()
Dim lastrow As Long
Dim rrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
rrows = lastrow / 4
MsgBox rrows 'returns 34.5 if lastrow is 138
End Sub
Gord Dibben MS Excel MVP
>I have some VBA code as this:
>rrows=lastrow/4
>
>if lastrow is 138 then rrows should be 34.5 but I always get 34(no decimal)
>How do I fix that
>Thanks
Jim Cone - 30 Sep 2006 17:13 GMT
Gord,
Check rrow vs. rrows
Regards,
Jim Cone
San Francisco, USA
Sub test()
Dim lastrow As Long
Dim rrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
rrows = lastrow / 4
MsgBox rrows 'returns 34.5 if lastrow is 138
End Sub
Gord Dibben MS Excel MVP
Gord Dibben - 30 Sep 2006 17:34 GMT
You're right Jim
Remove the Dim rrow As Long
That's why it worked.......rrows was never Dimmed as Long.
If it had, the decimal would not be returned.
One advantage?? of not using Option Explicit<g>
Gord
>Gord,
>
[quoted text clipped - 13 lines]
>
>Gord Dibben MS Excel MVP