Solved

# Help split string in a text array

Posted on 2013-12-19
324 Views
Hi experts

I have an array a(i).

The array contains text like

1. The Beach
2. The Song
3. The Sun
The Sun

How do I split the existing array into two parts:
(1) is the text up to the full stop eg 1.
(2) is the balance of the text eg The Beach
If there is no fullstop "." (1) would be empty (2) would be the whole lot of the text.

Then I've got to populate my table. I can move through the table okay, I just not sure how to work with the splitting the text - it does my head in!

For k = 1 To i - 1
selection.range.text = (1)
selection.moveright wdcell, 1
selection.range.text = (2)
Next

0
Question by:Fi69
• 3
• 2

LVL 26

Expert Comment

ID: 39728906
If there is no fullstop "." (1) would be empty (2) would be the whole lot of the text.

There seems to be a flaw in the logic. How could one know where the old record ends and the new one begins without the period?
0

Author Comment

ID: 39728927
What if I try a different approach.

The text is coming from headings, they could be numbered on non numbered.

How do I grab the text from the right of the full stop?
0

LVL 26

Expert Comment

ID: 39728973
How are  you putting the headings into the array?
0

Author Comment

ID: 39729077
Yes. I've generated it from a Table of contents - level 1 only. Converted that TOC to plain text, then added each paragraph in as my array.
0

LVL 13

Accepted Solution

Shanan212 earned 500 total points
ID: 39729093
Try this/get what I am trying to do. If you have questions, please reply

``````Sub sample()

Dim a() As String, i As Long
Dim wdcell As Long
wdcell = 1
a = Split("1.The Beach,2.The Song,3.The Sun,The Sun", ",")

For i = 0 To UBound(a)
If Len(a(i)) > 0 Then
If InStr(a(i), ".") > 0 Then
Selection.Value = Left(a(i), InStr(a(i), "."))
Cells(ActiveCell.Row + wdcell, ActiveCell.Column + wdcell).Select
Selection.Value = Mid(a(i), InStr(a(i), ".") + 1, Len(a(i)))
Else
Selection.Value = vbNullString
Cells(ActiveCell.Row + wdcell, ActiveCell.Column + wdcell).Select
Selection.Value = a(i)
End If

End If
Cells(ActiveCell.Row + wdcell, ActiveCell.Column + wdcell).Select
Next i
End Sub
``````
0

Author Comment

ID: 39729142
That's perfect. Thank you so much!!!!
0

## Featured Post

### Suggested Solutions

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …