Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

Help split string in a text array

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

Can someone please help me get (1) and (2) from my array a(i) please.
0
Fi69
Asked:
Fi69
  • 3
  • 2
1 Solution
 
MacroShadowCommented:
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
 
Fi69Author Commented:
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
 
MacroShadowCommented:
How are  you putting the headings into the array?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Fi69Author Commented:
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
 
Shanan212Commented:
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

Open in new window

0
 
Fi69Author Commented:
That's perfect. Thank you so much!!!!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now