While what @EricJ. answered is valid, there are other ways to test for the 0.1 value directly... without the need to test for a small range around it.
One of these is to convert to the Decimal variant subtype, which does not suffer from the imprecision of the Double, Single, or Date types.
Consider this procedure. It will never finish because of the imprecision of the Double:
Sub Bad()
Dim k As Double
k = 0
Do Until k = 0.1
k = k + 0.001
DoEvents
Loop
MsgBox k
End Sub
Now consider this, which finishes instantly:
Sub Good()
Dim k As Variant ' <-- look here
k = CDec(0) ' <-- look here
Do Until k = 0.1
k = k + 0.001
DoEvents
Loop
MsgBox k
End Sub
Answer for @Jolien.A question:
Define functionDerived
as a variant and use CDec() on the expression to the right of the equal sign.
And this is an even better approach, though it would not work in OP's case:
Sub Better()
Dim k As Double
k = 0
Do Until k = 0.1@ ' <-- look here
k = k + 0.001
DoEvents
Loop
MsgBox k
End Sub
This one is even quicker because the iterator (k) is kept as a Double. Notice the At-Sign (@) at the end of Do Until k = 0.1@
The At-Sign is the Decimal Type Character and using it as a suffix for a literal numeric value instructs the VBA compiler that the number is a Decimal, and not a Double (which is the default for fractional, literal numbers.
.
ADDITIONAL DETAILS
From MSDN: https://msdn.microsoft.com/en-us/library/xtba3z33.aspx
The Decimal Data Type:
Holds signed 128-bit (16-byte) values
It supports up to 29 significant digits
It is particularly suitable for calculations, such as financial, that require a large number of digits but cannot tolerate rounding errors.
largest value is +/-7.9228162514264337593543950335, and the smallest nonzero value is +/-0.0000000000000000000000000001 (+/-1E-28).
Decimal is not a floating-point data type. The Decimal structure holds a binary integer value, together with a sign bit and an integer scaling factor that specifies what portion of the value is a decimal fraction. Because of this, Decimal numbers have a more precise representation in memory than floating-point types (Single and Double).
The Decimal data type is the slowest of all the numeric types. You should weigh the importance of precision against performance before choosing a data type.