Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim myLimit As Integer, x, txt As String, i As Integer
myLimit = 5
With Me.TextBox1
If Len(.Text) = 0 Then Exit Sub
x = Split(.Text, vbLf)
If UBound(x) <= myLimit -1 Then Exit Sub
MsgBox "Allowed only " & myLimit & " lines in this box"
For i = 0 To myLimit -1
txt = txt & x(i) & vbLf
Next
.Text = Left(txt, Len(txt) - 1)
End With
End Sub
For one line only... couldn't you just set the MultiLine property to False and eliminate the above code altogether?In the userform module, modify for textbox name.
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If TextBox1.LineCount > 1 Then
KeyAscii = 0
MsgBox "Only 1 line is permitted", 48, "One line only."
Exit Sub
End If
End Sub
Hi Tom,In the userform module, modify for textbox name.
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If TextBox1.LineCount > 1 Then
KeyAscii = 0
MsgBox "Only 1 line is permitted", 48, "One line only."
Exit Sub
End If
End Sub