when yo run this vba script, 0.1 does not get add properly , sometimes its just 0.0999999 but not 0.1 always

adityavostro

New Member
Joined
Feb 21, 2018
Messages
3
Option Explicit
Private Sub CommandButton1_Click()


Dim mynumber1 As Double
mynumber1 = mynumber1textbox.Text

Dim myrange As Range
Set myrange = ActiveCell 'currently does not support user input for a particular cell
myrange = "Table of " & mynumber1


Dim mymoverate As Single
mymoverate = mymoverate1textbox.Text

Dim mynumber2 As Double
mynumber2 = mynumber2textbox.Text


Dim myvariable1 As Single
myvariable1 = 1


Dim myloopvariable As Integer
myloopvariable = 1


Dim mytestvariable1 As Single


Do While myvariable1 <= mynumber2 'currently does not support anylysation of errorfree mynumber2
myrange.Offset(myloopvariable, 0).Value = mynumber1 & " X " & myvariable1 & " = " & mynumber1 * myvariable1
myrange.Offset(myloopvariable, 0).Columns.AutoFit
myvariable1 = (myvariable1 + 0.1) 'mymoverate
mytestvariable1 = myvariable1
'If mytestvariable1 = 2.1 Then GoTo jmp


'If mytestvariable1 = 2.2 Then GoTo jmp


myloopvariable = myloopvariable + 1
Loop


Unload Me
jmp:
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Re: HELP URGENT PLEASE - when yo run this vba script, 0.1 does not get add properly , sometimes its just 0.0999999 but not 0.1 always


Not sure if this helps but should it not be


Dim mymoverate As Single

mymoverate = mymoverate1textbox.Text .......
mymoverate = mymoverate1textbox.
Value
<strike></strike>

Dim mynumber2 As Double
mynumber2 = mynumber2textbox.Text...........
mynumber2 = mynumber2textbox
.Value
 
Upvote 0
Re: HELP URGENT PLEASE - when yo run this vba script, 0.1 does not get add properly , sometimes its just 0.0999999 but not 0.1 always

i have tried replacing text with value. The problem is still there.

The problem in simple code:

Do until x>10
x=x+0.1
msgbox ("the result is " & x)

---

and if x is for example 2, then after 2.5 in my exel it shows 2.6 but then 2.6999999 then 2.799999

What could be the problem?
 
Upvote 0
Re: HELP URGENT PLEASE - when yo run this vba script, 0.1 does not get add properly , sometimes its just 0.0999999 but not 0.1 always

Correction Do until x<10
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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