number not copied correctly from form to a cell

Excel newbie

New Member
Joined
Jun 17, 2005
Messages
11
I have a form to enter some custom data into a worksheet. However the data entered into the form is not copied exactly as is onto the worksheet.

This is the code from the form that copied the value into the cell:

ActiveCell.Offset(0, 4).Activate
ActiveCell.Value = mach

mach is a single, the number i entered into the form

But the number I entered into the form is alway slightly off when copied into the cell. For example, if i enter 0.8 into the form, the cell value read 0.80000001. It cause my if statement to return false when I check for mach<=0.8.

How do I fix it so that the value copied is exact?
Thanks in advance
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Excel newbie said:
I have a form to enter some custom data into a worksheet. However the data entered into the form is not copied exactly as is onto the worksheet.

This is the code from the form that copied the value into the cell:

ActiveCell.Offset(0, 4).Activate
ActiveCell.Value = mach

mach is a single, the number i entered into the form

But the number I entered into the form is alway slightly off when copied into the cell. For example, if i enter 0.8 into the form, the cell value read 0.80000001. It cause my if statement to return false when I check for mach<=0.8.

How do I fix it so that the value copied is exact?
Thanks in advance

Probably a floating point issue. How is mach dim'd?

BTW, you can use:

ActiveCell.Offset(0, 4).Value = mach

and avoid Activate.
 
Upvote 0
Dim mach As Single

I figured it was a floating point issue too, but can't figure out how to solve it. Still a newbie in Excel and VB.

And thanks for the tip.
 
Upvote 0
Excel newbie said:
Dim mach As Single

I figured it was a floating point issue too, but can't figure out how to solve it. Still a newbie in Excel and VB.

And thanks for the tip.

Maybe

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> foo()
<SPAN style="color:#00007F">Dim</SPAN> x <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
x = Application.InputBox("enter value")
[a1].Value = x + 0
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,196,483
Messages
6,015,463
Members
441,898
Latest member
kofafa

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