Group:  Microsoft Excel ยป microsoft.public.excel.newusers
Thread: VBA code and decimals

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

VBA code and decimals
pcor 30.09.2006 14:49:01
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
Re: VBA code and decimals
"Don Guillett" <dguillett1[ at ]austin.rr.com> 30.09.2006 15:05:29
I just did this and got 34.5

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

--
Don Guillett
SalesAid Software
dguillett1[ at ]austin.rr.com
"pcor" <pcor[ at ]discussions.microsoft.com> wrote in message
news:F21838BC-42AA-48A3-9B0C-D2139287A187[ at ]microsoft.com...
[Quoted Text]
>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


Re: VBA code and decimals
Andy Pope <andy[ at ]andypope.info> 30.09.2006 15:05:29
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:
[Quoted Text]
> 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
Re: VBA code and decimals
pcor 30.09.2006 15:46:02
That did it....Thanks
Ian M

"Andy Pope" wrote:

[Quoted Text]
> 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
>
Re: VBA code and decimals
Gord Dibben <gorddibbATshawDOTca> 30.09.2006 16:01:21
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 <pcor[ at ]discussions.microsoft.com> wrote:

[Quoted Text]
>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

Re: VBA code and decimals
"Jim Cone" <jim.coneXXX[ at ]rcn.comXXX> 30.09.2006 16:13:57
Gord,

Check rrow vs. rrows

Regards,
Jim Cone
San Francisco, USA


"Gord Dibben" <gorddibbATshawDOTca>
wrote in message
news:v15th2hjk7rqbt79dsb5desejdtuledfun[ at ]4ax.com...
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

Re: VBA code and decimals
Gord Dibben <gorddibbATshawDOTca> 30.09.2006 16:34:43
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" <jim.coneXXX[ at ]rcn.comXXX> wrote:

[Quoted Text]
>Gord,
>
>Check rrow vs. rrows
>
>Regards,
>Jim Cone
>San Francisco, USA
>
>
>"Gord Dibben" <gorddibbATshawDOTca>
>wrote in message
>news:v15th2hjk7rqbt79dsb5desejdtuledfun[ at ]4ax.com...
>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

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net