#1
|
|||
|
|||
Number format in Textbox on userform
I have a basic userform with textboxes for data entry. Is it possible to format the data so when it goes to the spreadsheet, that it will stay in number format instead of changing the cell format to text?
This is what they currently look like. Code:
Private Sub TextBox1_Change() Sheets("Sheet1").Range("B25").Value = Me.TextBox1 End Sub Thank you. |
#2
|
|||
|
|||
You could try any of these.
Code:
Private Sub UserForm_Initialize() TextBox1 = Range("B1").Value TextBox2.Value = Format(Range("B1"), "$###.00") TextBox3 = Sheets("Sheet1").Range("B1").Text TextBox4.Value = Format(Range("B1"), "$###.##") TextBox5.Value = Format(Range("B1"), "$0,000.00") End Sub |
#3
|
||||
|
||||
Textboxes contain string data types. If your users are entering numbers then you can explicitly convert the string into a number (numbers in worksheets are always double data types), for example:
Code:
Private Sub TextBox1_Change() Sheets("Sheet1").Range("B25").Value = CDbl(Me.TextBox1.Value) End Sub Code:
Private Sub TextBox1_Change() Sheets("Sheet1").Range("B25").Value = Val(Me.TextBox1.Value) End Sub |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Custom Number Format for Chart | deadrxn24 | Word | 4 | 03-18-2012 05:38 PM |
custom number format: change thousands separator | Ward | Excel | 1 | 06-07-2011 08:18 PM |
Textbox Number changes when I open Word | t0m46 | Word VBA | 0 | 09-07-2010 05:46 AM |
Numbering, defining new number format | nrschmid | Word | 0 | 12-30-2009 03:04 PM |
Default Number Format | boutells | Excel | 1 | 05-20-2009 02:46 PM |