
How to write textbox entries (values with more than two decimals) to Excel cells?
While writing data from a userform (VBA) to an excel worksheet I
receive confusing results depending on the formats and conversions
used.
Example 1 (using "," as separator for decimals):
I enter 12,34567890 to a textbox and use the VBA-line
<worksheet>.Cells(x, y).Value = Format(CSng(TextBox1.Value), "0.00")
to write the value to the desired cell.
The result is 12,35 (which is what i expected)
Example 2:
I enter 12,34567890 to a textbox and:
<worksheet>.Cells(x, y).Value = Format(CSng(TextBox1.Value), "0.0000")
The result is 123457,0000 (I expected 12,3457 instead)
Example 3 (without format()):
I enter 12,34567890 to a textbox and:
<worksheet>.Cells(x, y).Value = CSng(TextBox1.Value)
The result is 12,34567928 (I expected 12,3456789 instead)
I would be very glad if somebody could explain these effects and give
solutions.