ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   user form (https://www.excelbanter.com/excel-discussion-misc-queries/181227-user-form.html)

jase

user form
 
I am using a userform on an excel sheet that has a text box which reads
values off a designated cell in the sheet. On my userform the cell value is
rounded to about 8 decimal places and I would only like it to round to 1 or
2. Any idea how I would do that? On the excel sheet I have it rounded to 2
and that doesn't seem to work.

Tom Hutchins

user form
 
One way... Load the cell value into a variable, use the Round function in VBA
to round it to as many decimals as you want, and assign the value of the
(rounded) variable to the textbox's value.

Private Sub UserForm_Initialize()
Dim CellVal As Double
CellVal# = Round(Sheets("Sheet1").Range("B30").Value, 2)
Me.TextBox1.Value = CellVal#
End Sub

Hope this helps,

Hutch

"Jase" wrote:

I am using a userform on an excel sheet that has a text box which reads
values off a designated cell in the sheet. On my userform the cell value is
rounded to about 8 decimal places and I would only like it to round to 1 or
2. Any idea how I would do that? On the excel sheet I have it rounded to 2
and that doesn't seem to work.



All times are GMT +1. The time now is 01:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com