Solved

Help split string in a text array

Posted on 2013-12-19
6
327 Views
Last Modified: 2013-12-19
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
Comment
Question by:Fi69
  • 3
  • 2
6 Comments
 
LVL 27

Expert Comment

by:MacroShadow
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

by:Fi69
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 27

Expert Comment

by:MacroShadow
ID: 39728973
How are  you putting the headings into the array?
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:Fi69
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

by:
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

Open in new window

0
 

Author Comment

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

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
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 …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question