• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Display line numbers in a multiline userform textbox

inddon

Member
Hello There,

In my Userform I have a multiline textbox. The user can load a file content in this textbox as well as they can enter it manually (multi lines).
I would like to display line numbers for each line for this textbox. I am not aware, if this could be displayed in the textbox itself. Therefore, I have created the following:
1. TextboxLineNumbers (Multiline, no scrollbars, no updatable by user)
2. TextboxComments (Multiline, scrollbars)

The action performed in TextboxComments should reflect in TextboxLineNumbers (delete, insert, scroll movement).

Could someone let me know the VBA code to get the above working?

I have attached the sample workbook for your reference.


75133


Thank you & regards,
Don
 

Attachments

Hui

Excel Ninja
Staff member
Try the following in the Comments Text Box

Code:
Private Sub TextBoxComments_Change()

TextBoxLineNumber.Text = ""

For i = 1 To Len(TextBoxComments.Text) - Len(Replace(TextBoxComments.Text, Chr(13), "", 1)) + 1
   TextBoxLineNumber.Text = TextBoxLineNumber + CStr(i) + Chr(10)
Next
End Sub
 

inddon

Member
Try the following in the Comments Text Box

Code:
Private Sub TextBoxComments_Change()

TextBoxLineNumber.Text = ""

For i = 1 To Len(TextBoxComments.Text) - Len(Replace(TextBoxComments.Text, Chr(13), "", 1)) + 1
   TextBoxLineNumber.Text = TextBoxLineNumber + CStr(i) + Chr(10)
Next
End Sub

Thank you Hui for the code. Nice to hear from you after a long time.

You code does work untill the TextBoxLineNumber display ends.

If I enter more lines in the comment (eg. enter line with wordwrap, enter lines beyond the Comments display - Vertical scrollbar seen), the LineNumber does not get in sync with the Comments.

For your reference, below snapshot:

75157


Regards,
Don
 
Top