Round textbox value

mike0123m

Board Regular
Joined
Jul 25, 2007
Messages
93
I have a userform that copies the value of a cell to a textbox on the userform. I want to round the value two one decimal place in the textbox. This is the code I have but I keep getting a run-time error 13:

TextBox7.Text = Round(Sheets("sheet3").Range("w51").Value, 0)

I can see why I get the error but I don't know how else to get the value from the cell into a textbox and round the value to one decimal place.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
You shouldn't get that error unless the value of your cell W51 is non-numeric.

Also, if you want it to round to 1 decimal place, you should use a 1 at the end, not a 0.

Code:
TextBox7.Text = Round(Sheets("sheet3").Range("w51").Value, 1)

If it is a number stored as text, I think you could use something like this:

Code:
TextBox7.Value = Round(val(Sheets("sheet3").Range("w51").value), 1)
 
Last edited:
Upvote 0
Nogslaw - the second solution works great but how can I get the textbox to remain empty if the value in the cell on the worksheet is 0 or if the cell is blank?
 
Upvote 0
Sorry for the late response ... I was on vacation all last week. Here is one way that you can make that happen:

Code:
If Sheets("Sheet3").Range("W51").Value <> "" And Val(Sheets("Sheet3").Range("W51").Value) <> 0 Then
    TextBox7.Value = Round(Val(Sheets("Sheet3").Range("W51").Value), 1)
Else:  TextBox7.Value = ""
End If
 
Upvote 0

Forum statistics

Threads
1,224,581
Messages
6,179,668
Members
452,936
Latest member
anamikabhargaw

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