macro is rounding up and down (1 Viewer)

smiler44

Registered User.
Local time
Today, 06:43
Joined
Jul 15, 2008
Messages
641
I have a macro comparing the value of two cells next to each other but 39.99 is being rounded up to 40 and 33.17 rounded down to 33.
I have no idea why or how to cure it, please can you advise?
Below is my code and it is Excel 2007

thank you

Dim rt As String ' number of times
Dim ev As Integer
Dim rv As Integer


Sub loss()

Range("B7").Activate
Do Until ActiveCell.Value = ""
If ActiveCell.Value = 1 Then
ActiveCell.Offset(0, 3).Activate 'across 3
ev = ActiveCell.Value
ActiveCell.Offset(0, 1).Activate
rv = ActiveCell.Value
ActiveCell.Offset(1, -4).Activate
Else
ActiveCell.Offset(1, 0).Select 'down 1 across 0
GoTo nxt
End If

If ev > rv Then
rt = rt + 1
ev = "0"
rv = "0"
MsgBox ("ev greater then rv")
End If

nxt:
Loop

End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:43
Joined
Aug 30, 2003
Messages
36,124
The Integer data type can't hold a decimal. I'd use Currency.
 

smiler44

Registered User.
Local time
Today, 06:43
Joined
Jul 15, 2008
Messages
641
The Integer data type can't hold a decimal. I'd use Currency.
thank you pbaldy, currency has worked. I never knew integer could not deal with decimals.

smiler44
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 22:43
Joined
Aug 30, 2003
Messages
36,124
Happy to help!
 

Users who are viewing this thread

Top Bottom