Formatting decimal places

tnapele

New Member
Joined
Mar 27, 2020
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hello!

I have a excel worksheet that uses Vlookups in the cells of the worksheet to plug data into a userform. The Vlookups get the data from a separate worksheet that has a ton of decimals (ie. 2500.7256416436) but I would like to change specific ones to have 2 decimals and others to have no decimals. Is there a way I can do this?
I have tried to format the excel doc outside of VBA but it just re formats to all the extra numbers when I run the code.
I've tried Me.TextBox2.Value = Format(Me.TextBox1.Value, "0.00") and a few other things in the code but nothing I try seems to be working.
Thanks for any guidance!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Cell A1 = 2500.7256416436
Cell B1 = =round(A1,0)
Cell B1 Value = 2501
Cell C1 = =Round(A1,2)
Cell C1 Value = 2500.73

Replace ROUND with ROUNDUP or ROUNDDOWN to force the logic, otherwise based on 0.5 or greater math logic

Does this help?
 
Upvote 0
Braindiesel,
This would help but unfortunately the data is being pulled from another source and placed onto an already full worksheet. I was hoping for a code that I could add or find a way to do it within just one cell. I appreciate your help though!
 
Upvote 0
Shouldn't it be
Rich (BB code):
 Me.TextBox2.Value = Format(Me.TextBox2.Value, "0.00")
 
Upvote 0
Fluff,
I tried that in my code but it doesn't seem to be working. Is there a way to format textboxes in userforms? I can format the excel document however I want but then I run my code and my userform always comes up with a lot of decimals. Thanks for your help!
 
Upvote 0
Yes you can format textboxes, exactly as shown.
Do you have any change code for that textbox?
 
Upvote 0
1593630742672.png

Here is a photo of the userform I have. Data is pulled on to this userform from another excel doc that is monitoring our systems constantly. Then the data from this user form overwrites the data in this worksheet to update it.
 
Upvote 0
I'm not sure what change code is, there are a few codes that the text boxes have
 
Upvote 0
Can you post all the code?
 
Upvote 0
I screenshotted but let me know if you would like the text of any of these! This is anywhere where the code for the "Steam produced" on a specific boiler is located.
1593631618570.png


1593631630101.png


1593631640170.png
 
Upvote 0

Forum statistics

Threads
1,223,596
Messages
6,173,258
Members
452,506
Latest member
Bradnewbie

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