IF/Then statement not working

Photomofo

Active Member
Joined
Aug 20, 2012
Messages
259
For some reason the if statement in the code below isn't picking up when it should. I can see that on step 69 it should pick up but it's not seeing 3 = 3 as true. I think it's something to do with the Data array.

Code:
Sub XYZ()


Dim i As Long
Dim Speed as double



Data = Sheets("Data").Range("A1:WK609")


For i = 130 To 130


    Speed = 0
    
    For j = 1 To 609

        If j >9 then

               Speed = Speed + .05

        end if

    

        If Data(1, j) = Speed Then
        
        Stop
        
        End If
    
    Next j
    
Next i


End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
It will most likely be an Excel calculation/storage rounding error. Try this adjustment
Code:
Speed = Round(Speed + 0.05, 2)
 
Upvote 0
Thanks Peter...

I had a string of equations in row 1 that went A1+.05 all the way to column WK... you'd think all the values would go 0, .05, .1, .15 and so on... In column RB the value is 23.0500000000002... Go figure.

I used a slightly different solution but your suggestion would have fixed this as well.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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