Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Help with lookup | Excel Discussion (Misc queries) | |||
Fixed decimals worksheet specific | Excel Worksheet Functions | |||
Want Fixed Decimal places in only 1 column | Excel Discussion (Misc queries) | |||
Sorting Numbers with Multiple Decimals (cont.) | Excel Discussion (Misc queries) | |||
How can I format the #of decimals, field types, etc. automaticall. | Excel Discussion (Misc queries) |