VBA code and decimals

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
I just did this and got 34.5

Sub lastrowdecimal()
lastrow = 138
rrows = lastrow / 4
MsgBox rrows
End Sub
 
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
 
That did it....Thanks
Ian M

Andy Pope said:
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
 
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,

Check rrow vs. rrows

Regards,
Jim Cone
San Francisco, USA


"Gord Dibben" <gorddibbATshawDOTca>
wrote in message
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
 
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
 
Back
Top