ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Count characters in 1st line of UserForm Textbox (https://www.excelbanter.com/excel-programming/383041-count-characters-1st-line-userform-textbox.html)

PCLIVE

Count characters in 1st line of UserForm Textbox
 
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



Chip Pearson

Count characters in 1st line of UserForm Textbox
 
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)


"PCLIVE" wrote in message
...
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





NickHK

Count characters in 1st line of UserForm Textbox
 
Paul,
Can you use a fixed-width font, then calculation would be possible.

NickHK

"PCLIVE" wrote in message
...
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






All times are GMT +1. The time now is 01:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com