I have a loop that takes a number from the user, tests an Excel document for instances of this number, and then subtracts one tenth from the input number, and tests again. The loop operates until the number ends up at zero.
Now the problem that I have is after two or three loops the result of the Input = Input - 0.1 begins resulting in a number with several decimal places when I want to keep it to just one. (i.e. at the the third time the loop operates starting at 1 it results in 0.6999999 instead of just 0.7.
I need it to remain at the one decimal place so I get an even number each time, in sequence (i.e. 1, 0.9, 0.8, 0.7 and so on until Zero.) I'm using Single data type. Is there a better data type to use?
Private Sub btnProcess_Click()
Dim strPercent2 As String
strPercent2 = Me.txtPercentage.Value
Dim sngPercent2 As Single
Dim strSearch As String
If IsNumeric(strPercent2) Then
sngPercent2 = CSng(strPercent2)
Do While sngPercent2 > 0.1
strSearch = CStr(sngPercent2)
Dim i As Long
i = 1
Do Until i > Cells(65536, "a").End(xlUp).Row
If InStr(Trim(Cells(i, "a").Value), strSearch) > 0 Then
Rows(i - 1 & ":" & i + 3).delete
i = i + 1
Application.ScreenUpdating = True
sngPercent2 = sngPercent2 - 0.1