View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default For Next bug ????

Probably a rounding thing. i is probably close to 1.4 but not quite. With
fpp, it's approximations but it's good enough for most situations.
Suggest you write something like

Dim i as Long

For i = 0 to 2
Debug.Print i * 0.2 + 1
Next


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Nick" wrote in message
...
In Excel 2002 I have written the following code

Private Sub Test()
Dim i As Double

For i = 1 To 1.4 Step 0.2
Debug.Print i
Next
End Sub

Producing the following text in the debug window
1
1.2

I would expect
1
1.2
1.4

By changing the code to:

Private Sub Test()
Dim i As Double

For i = 1 To 1.6 Step 0.2
Debug.Print i
Next
End Sub

I get what I would expect:
1
1.2
1.4
1.6

Does anyone know why???? I also get this in Excel 2000