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 show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
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,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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