Count characters in 1st line of UserForm Textbox

P

PCLIVE

To count all of the characters (including spaces) in a UserForm Textbox, I
can use:

Len(UserForm1.DayList.Text)

Is there a way to just count the number of characters that are in the first
line of that textbox?

Thanks,
Paul
 
C

Chip Pearson

If the lines of text in the text box are separated by line break characters,
you could use code like

Dim Pos As Integer
Me.TextBox1.Text = "first line" & vbNewLine & _
"second line"
Pos = InStr(1, Me.TextBox1.Text, vbNewLine)
If Pos > 0 Then
MsgBox "Line 1 Length: " & Pos - 1
End If

If there are no line break characters, I don't think you can parse out just
the first line.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top