Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 148
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 10,124
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 2,489
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 148
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 22,906
Default 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




  #6   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 3,290
Default 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

  #7   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 22,906
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with lookup Bob Excel Discussion (Misc queries) 10 September 23rd 06 08:19 AM
Fixed decimals worksheet specific Charlotte Excel Worksheet Functions 7 September 14th 06 02:33 PM
Want Fixed Decimal places in only 1 column MikeElectricUtility Excel Discussion (Misc queries) 4 July 12th 06 09:11 PM
Sorting Numbers with Multiple Decimals (cont.) Intern Ian Excel Discussion (Misc queries) 5 September 21st 05 12:04 AM
How can I format the #of decimals, field types, etc. automaticall. JOET Excel Discussion (Misc queries) 1 April 2nd 05 12:14 AM


All times are GMT +1. The time now is 08:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"