Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
text box tab problem
A few days ago I posed the following questions:
"I have a text box on a user form and I want to format it so the user has to enter numbers (with a decimal) and the result needs to be displayed in the text box as currency. I don't want it to allow text. ??? SDC" Here was an excellent answer: "Hi SDC Userform code: Private Sub TextBox1_Enter() TextBox1.SelStart = 0 TextBox1.SelLength = Len(TextBox1.Text) End Sub Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case 8 To 10, 13, 27, 32 'Control characters Case 44, 46 'comma, dot If InStr(TextBox1.Text, ".") = 0 Then KeyAscii = 46 Else KeyAscii = 0 End If Case 45 'minus If TextBox1.SelStart = 0 And InStr (TextBox1.Text, "-") = 0 Then Else KeyAscii = 0 End If Case 48 To 57 'numbers Case Else 'Discard anything else KeyAscii = 0 End Select End Sub Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) Dim D As Double D = CDbl(TextBox1.Text) TextBox1.Text = Format(D, "Currency") End Sub -- HTH. Best wishes Harald Excel MVP" However, when I tab out of my text box the next tab stop is a command button. The text in the text box does not convert to currency when tabbing to a command button. To convert to currency, I have to select another text box??? SDC |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Countif - problem counting text, other text | Excel Worksheet Functions | |||
Text Display Problem. | Excel Discussion (Misc queries) | |||
Text Box problem | Excel Discussion (Misc queries) | |||
Large amount of text in cells - Problem text.xls (0/1) | Excel Discussion (Misc queries) | |||
Large amount of text in cells - Problem text.xls (1/1) | Excel Discussion (Misc queries) |