Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / September 2006

Tip: Looking for answers? Try searching our database.

VBA code and decimals

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pcor - 30 Sep 2006 15:49 GMT
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

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.