VBA is rounding up or down when it shouldn't

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
516
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have an odd one. The purpose of the code is pull out the fastest runners, and then copy the data to another sheet.
The speeds are being pulled from a pivot table.
The pivot table has speeds with two decimal places - no drama.
If I do an = sign and refer to the pivot table cell, I still get two decimal places - no drama.
However, when I use this code, if the referenced cell is <16.5, the result is being rounded down to 16 and if the reference cell is above 16.5, the result is being rounded up to 17.

I thought it might have something to do with Floating points, but that was fruitless.

A msgbox directly after the Speed = .Range("GV" & ii).Value line shows the value has already been rounded.

Any ideas ????
I am stumped on what appears to be a very simple exercise.

Thanks in advance.

VBA Code:
Sub FindFastest()
Dim Speed as Long, irow As Long, ii As Long
With Sheet1
    For ii = 2 To 25
        If .Range("GV" & ii).Value >= 16 Then
            Speed = .Range("GV" & ii).Value
           
            With Sheet34
                'last row - need to find each time
                 irow = .Range("BA30").End(xlUp).Row + 1
                .Range("BD" & irow).Value = Speed
            End With
        End If
      Next
End With
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I'll b a monkeys uncle. I have never had this issue before and using the right decaration fixed it.

Thanks FormR
 
Upvote 0
using the right decaration fixed it.

Thanks FormR
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,215,092
Messages
6,123,063
Members
449,090
Latest member
fragment

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top