Reputation:
I have a word list for example: Jacob Matt Ben Don
I want to make them like this.
Jacob
Matt
Ben
Don
Anyone know how?
Upvotes: 0
Views: 111
Reputation: 355
This will do it for you. You'll just have to set it up the way you want to call it. but this code will take your string and break on spaces in to an array of undefined proportion. Then write each populated element in the array to the document.
Private Sub test()
Dim MyLine As String
Dim MyArray() As String
Dim MyCounter As Integer
MyLine = "Jacob Matt Ben Don"
MyArray = Split(MyLine, " ")
MyCounter = 0
On Error GoTo Done
While MyArray(MyCounter) > ""
ActiveDocument.Content.InsertAfter Text:=MyArray(MyCounter) & Chr(11)
MyCounter = MyCounter + 1
Wend
Done:
End Sub
Upvotes: 0
Reputation: 8365
So, did this for a challenge, guaranteed to be better ways with vba, but wanted to make something with functions only...
With the target text in cell A1, then cell A2 has the following dragged down to A4:
=RIGHT(A1,LEN(A1)-LEN(B1)-1)
In cell B1 dragged down to B4 is:
TRIM(IFERROR(LEFT(A1,FIND(" ",A1,1)-1),A1))
Upvotes: 0