Solved

Help split string in a text array

Posted on 2013-12-19
6
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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