More Textbox questions

T

thesteelmaker

Using the code below i can enter a numeric value to a textbox, whic
ends up as 2 decimal places (in the textbox).

But when entered to cell "A1" the format is still "General".

i.e. if i enter 6.1 into my textbox it ends up as 6.1 on the s/shee
and not as 6.10 as i want it.

Any help.
Thanks

Private Sub cmbAdd_Click()
' Select sheet and cell
ActiveWorkbook.Sheets("Sheet1").Activate
Range("A1").Select

' Format and enter data
TextBox1.Text = Format$(UserForm1.TextBox1.Text, "####0.00")

' Varify numeric
If IsNumeric(TextBox1) = False Then
MsgBox "You inserted a non-numeric, try again."
TextBox1.SetFocus
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
Exit Sub
Else
ActiveCell.Value = TextBox1.Text
End If

' Clear box after adding data
TextBox1.Text = ""
End Sub

Private Sub UserForm_Initialize()
TextBox1.Text = ""
TextBox1.SetFocus
End Su
 
B

Bob Phillips

Use

ActiveCell.Value = Format(TextBox1.Text,"#,##0.00")


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top