ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   VBA code and decimals (https://www.excelbanter.com/new-users-excel/112317-vba-code-decimals.html)

pcor

VBA code and decimals
 
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

Andy Pope

VBA code and decimals
 
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

pcor wrote:
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


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

Don Guillett

VBA code and decimals
 
I just did this and got 34.5

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

--
Don Guillett
SalesAid Software

"pcor" wrote in message
...
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




pcor

VBA code and decimals
 
That did it....Thanks
Ian M

"Andy Pope" wrote:

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

pcor wrote:
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


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info


Gord Dibben

VBA code and decimals
 
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

On Sat, 30 Sep 2006 07:49:01 -0700, pcor wrote:

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

VBA code and decimals
 
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


Gord Dibben

VBA code and decimals
 
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

On Sat, 30 Sep 2006 09:13:57 -0700, "Jim Cone" wrote:

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




All times are GMT +1. The time now is 07:15 PM.

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