Hello, I am trying to create a line count to display to the end user how many lines are entered in the multiline textbox. (either label or textbox to display counter start at 0)
The current code I have is:
Private Sub TextBox1_Change() 'automated changes when textbox changes
With CreateObject("VBScript.RegExp")
CheckLimit
.MultiLine = True: .Global = True
.Pattern = "^\r\n"
Me.TextBox1.Text = .Replace(Me.TextBox1.Text, "")
.Pattern = "(.*(^[^\n]+\n)[^\2]*)(^\2)(\n|$)"
If .test(Me.TextBox1.Text) Then
Me.TextBox1.Text = .Replace(Me.TextBox1.Text, "$1")
End If
End With
End Sub
Private Sub CheckLimit() 'limit textbox msg
'Declare Values
Dim temp As String
Dim Linecount As String
Linecount = TextBox2.Value
Linecount = Label8.Caption
qtyset = ActiveSheet.Range("G9").Value
numlimit = qtyset - 1
'Enter is now a return key in this textbox1 filed
If KeyCode = vbKeyReturn Then
TextBox1.Text = Replace(TextBox1.Text, vbCrLf, "")
End If
'textbox QTY as limit coding
If TextBox1.CurLine > numlimit Then ' 0-based
display = MsgBox("Input can't be more than " & qtyset & " lines.", vbCritical)
temp = TextBox1.Text
If Right$(temp, 2) = vbCrLf Then
temp = Left$(temp, Len(temp) - 2)
Else
temp = Left$(temp, Len(temp) - 1)
End If
End If
End Sub
Bookmarks