Is it possible to extract strings from a Multi-Line TextBox?

dagda13

Board Regular
Joined
May 18, 2019
Messages
52
Hi,

I have an Multi-Line ActiveX TextBox1 that has the below strings as separate lines:

'Cat'
'Dog'
'Snake'
'Bear'
'Dragon'

I have TextBox1 linked to a single cell, so that it will output these lines to one cell. I'm trying to figure out a way (if indeed it's even possible) to output each line in TextBox1 so that, for example, you would have

B2 = 'Cat'
C2 = 'Dog'
D2 = 'Snake'
E2 = 'Bear'
F2 = 'Dragon'.

I've tried to add more than one LinkedCells in the TextBox1 Properties, but this doesn't work. Is it possible to somehow extract each string to its own cell? Thanks!
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Assuming the TextBox is on the active worksheet, this macro should do what you want...
Code:
Sub TextBoxToRow()
  Dim Arr As Variant
  Arr = Split(ActiveSheet.TextBox1.Text, vbLf)
  Range("B2").Resize(, UBound(Arr) + 1) = Arr
End Sub
 
Upvote 0
Hi Rick,

Thanks very much for the help! However, the input is still outputting all in one cell (B2). I've tried changing the Range both in the Properties and the code, but still no go. (And yes, this textbox is embedded directly in the worksheet).
 
Last edited:
Upvote 0
And sorry, this is totally my bad: What I'd like to do is to output the strings in multiple cells in the same column, ie.,

B2
B3
B4
B5
B6

Sorry again!
 
Last edited:
Upvote 0
Please help i tried searching exact word in a textbox multiline

but not working

Dim strVal As String

Static lastInstancePosition As Long ' use Static variable to have its value persist after Sub exiting
Dim instancePosition As Long


strVal = InputBox("Enter receipt number:", "Find")
With TextBox1
instancePosition = InStr(lastInstancePosition + 1, .Text, strVal) 'search string occurrence starting from last found item
If instancePosition > 0 Then
.SetFocus 'bring focus back ti the textbox after it has been taken by the button
.SelStart = instancePosition - 1
.SelLength = Len(strVal)
lastInstancePosition = instancePosition ' update starting position for next search
End If
End With
1654416693253.png
1654416742671.png

the Receipt #: 4 is not selected
Thanks in advance
 
Upvote 0
Finally i have solve the issue

Private Sub cmdsearch_Click()
Dim a() As String
Dim b As String
Dim strVal As String
Static lastInstancePosition As Long ' use Static variable to have its value persist after Sub exiting
Dim instancePosition As Long


strVal = InputBox("Enter receipt number:", "Find")

With TextBox1
a = Split(.Text, vbCrLf)
instancePosition = InStr(lastInstancePosition + 1, Join(a, vbLf), strVal) 'search string occurrence starting from last found item
If instancePosition > 0 Then
.SetFocus 'bring focus back to the textbox after it has been taken by the button
.SelStart = instancePosition - 1
.SelLength = Len(strVal)
lastInstancePosition = instancePosition ' update starting position for next search
End If
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top