Textbox formatting

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

Hey guys,

I still cannot get a $ sign to come up before everything I type in a
textbox.


I want to be able to type in lets say TextBox1 and when I do, the $ sign
pops up in front of the number. I need the dollar sign to always be there
no matter how many times I re-enter numbers and I need it to format the cell
as $0.00
 
Todd,

Try something like the following:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Left(Me.TextBox1.Text, 1) <> "$" Then
Me.TextBox1.Text = "$" & Me.TextBox1.Text
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
You can certainly add more checking to this, but basically (if I understand
the question) you can approach it like this:

Private Sub Textbox1_Change()
sStr = TextBox1.Text
If InStr(sStr, ".") Then
TextBox1.Text = _
Format(CDbl(Application.Substitute( _
TextBox1, "$", "")), "$ #.##")
Else
TextBox1.Text = _
Format(CDbl(Application.Substitute( _
sStr, "#$", "")), "$ #")
End If
End Sub
 
Todd,

This was previously suggested to you, and it works great for me.

Private Sub TextBox1_Enter()
TextBox1.Value = "$"
End Sub

Have you tried it?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
The if statements worked well and I put it in the change event. Now it
works great. Thank you both.

Todd
 
Back
Top