1

Can I loop through a Textbox for each line entered and format it? For example if the user entered:

Text1
Text2

I would like to output it as in a single line.

'Text1','Text2'

Also would be awesome if you can get the last comma to not display.

3
  • 1
    Bonus points? Bounty award? ;) Commented Mar 26, 2015 at 23:51
  • You want it with ' apostrophe right? Commented Mar 27, 2015 at 0:07
  • Just remove wrap text? Commented Mar 27, 2015 at 0:10

1 Answer 1

3

This is what you really need

  • Add a textbox to your sheet

  • Add this code on TextBox1_Change() event

    Dim mystr      
    
    mystr = Split(Sheet1.TextBox1.Text, vbCrLf)
    Sheet1.Range("A1") = "'" & Join(mystr, "','") & "'"
    
  • Right click to textbox and enable multiline option

  • Control + Enter to change line inside textbox

And you have the result that you want:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! That works wonderfully. I had it outputting in a test box instead of the sheet so I just replaced Sheet.Range("A1") with Textbox2.Text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.