VBA code and decimals

P

pcor

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
 
D

Don Guillett

I just did this and got 34.5

Sub lastrowdecimal()
lastrow = 138
rrows = lastrow / 4
MsgBox rrows
End Sub
 
A

Andy Pope

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
 
P

pcor

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
 
G

Gord Dibben

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
 
J

Jim Cone

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
 
G

Gord Dibben

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
 

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

Top