$ format in cell

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

Todd Huttenstine

Hey guys I had a code that did this but now I cant find
it!!!

What it does is as I type in a textbox it will put the $
sign in front of the number. So if I go to a textbox and
type 135, the dollar sign will be there at the front even
as I am typing.
 
Todd,

Here's one way


Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Static flag As Boolean

If flag <> True Then
TextBox1.Text = "$" & TextBox1.Text
flag = True
End If

End Sub

--

HTH

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

Dim OneShot As Boolean

Private Sub TextBox1_Change()
If Application.EnableEvents = False Then Exit Sub
If Not OneShot Then
OneShot = True
Application.EnableEvents = False
TextBox1.Value = "$ " & TextBox1.Value
Application.EnableEvents = True
End If
End Sub
 
THat works, but thats a little longer than the other code
I had. Also this code works but if I then clear
everything out of the textbox and try typing another
number in there, it does not put the $ at the front.
 
Todd

Is this what you want?

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

Regards
Peter
 
Back
Top