View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Executor Executor is offline
external usenet poster
 
Posts: 74
Default exact number of characters in textbox

Hi,

In this case you can use the Exit event for the textbox.

If you use this code it should work:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim intPos As Integer
If Len(TextBox1.Text) < 11 Then
MsgBox "PLEASE ENTER 11 DIGTIS", vbExclamation, "Retry"
Cancel = True
Else
For intPos = 1 To 11
If Not IsNumeric(Mid(TextBox1.Text, intPos, 1)) Then
MsgBox "Please use numbers only", vbExclamation,
"Retry"
Cancel = True
End If
Next
End If
End Sub

your user smust fill the textbox with 11 digits.
As a bonus I have added a check on numbers opnly.


HTH,

Wouter