How to extract some text from list in some order?

A

avkokin

Hello.
There is one document which has many numbered paragraphs (from 1 to 50
or different). I need to get from this list of some paragraphs
together for next order: 1 and 31, 2 and 32...30 and 50.
For example:
The number list view like:
1. Some text some text.
2. Other some text.
3. And more other text.
....
30. My some text.
31. My other some text.
32. My new other text.
....
50. Some text.

I heed to get it so:
1. Some text some text.
31. My other some text.

2. Other some text.
32. My new other text.

30. My some text.
50. Some text.

First I convert the numbered list to plain text. But what I should to
do next I'm not know. Maybe create array from selection text?
Help me, please.
Thank you very much.
 
D

Doug Robbins - Word MVP

Set a Range object to the list and then extract the required paragraphs

Dim OldList as Range
Set OldList = [the range of text that includes the list]
Set NewList = ActiveDocument.Range
NewList.Collapse wdCollapseEnd
With NewList
InsertAfter OldList.Paragraphs(1).Range & OldList.Paragraphs(31).Range &
etc.
End With




--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Anton Kokin

Hi. Sorry but if I set for range Selection.Range I got error. This my code:

Sub test_bilet()
Dim NewList As Range
Dim OldList As Range
Set OldList = Selection.Range
Set NewList = ActiveDocument.Range
NewList.Collapse wdCollapseEnd
With NewList
InsertAfter OldList.Paragraphs(1).Range & OldList.Paragraphs(31).Range &
vbCr
InsertAfter OldList.Paragraphs(2).Range & OldList.Paragraphs(32).Range &
vbCr
InsertAfter OldList.Paragraphs(3).Range & OldList.Paragraphs(33).Range &
vbCr
InsertAfter OldList.Paragraphs(4).Range & OldList.Paragraphs(34).Range &
vbCr
InsertAfter OldList.Paragraphs(5).Range & OldList.Paragraphs(35).Range &
vbCr
InsertAfter OldList.Paragraphs(6).Range & OldList.Paragraphs(36).Range &
vbCr
InsertAfter OldList.Paragraphs(7).Range & OldList.Paragraphs(37).Range &
vbCr
InsertAfter OldList.Paragraphs(8).Range & OldList.Paragraphs(38).Range &
vbCr
InsertAfter OldList.Paragraphs(9).Range & OldList.Paragraphs(39).Range &
vbCr
InsertAfter OldList.Paragraphs(10).Range & OldList.Paragraphs(40).Range &
vbCr
InsertAfter OldList.Paragraphs(11).Range & OldList.Paragraphs(41).Range &
vbCr
InsertAfter OldList.Paragraphs(12).Range & OldList.Paragraphs(42).Range &
vbCr
InsertAfter OldList.Paragraphs(13).Range & OldList.Paragraphs(43).Range &
vbCr
InsertAfter OldList.Paragraphs(14).Range & OldList.Paragraphs(44).Range &
vbCr
InsertAfter OldList.Paragraphs(15).Range & OldList.Paragraphs(45).Range &
vbCr
InsertAfter OldList.Paragraphs(16).Range & OldList.Paragraphs(46).Range &
vbCr
InsertAfter OldList.Paragraphs(17).Range & OldList.Paragraphs(47).Range &
vbCr
InsertAfter OldList.Paragraphs(18).Range & OldList.Paragraphs(48).Range &
vbCr
InsertAfter OldList.Paragraphs(19).Range & OldList.Paragraphs(49).Range &
vbCr
End With
End Sub
 
D

Doug Robbins - Word MVP

What line of code causes the error?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP

If you select the range of paragraphs and then run the following code, it
will sort them into the order that you want (deleting paragraphs 20 through
29, which did not appear to be used in your code)

Dim i As Long
Selection.Range.ConvertToTable
With Selection.Tables(1)
.Columns.Add BeforeColumn:=.Columns(1)
With .Columns(1)
For i = 1 To 19
.Cells(i).Range.Text = 2 * i - 1
Next i
For i = 30 To 49
.Cells(i).Range.Text = 2 * (i - 29)
Next i
End With
For i = 29 To 20 Step -1
.Rows(i).Delete
Next i
.Sort
.Columns(1).Delete
End With



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Anton Kokin

the error is "Sub or Function not defined" for property "Range" by
OldList.Paragraphs(1)>Range:

I selection text of numbered lis and apply this macro.
 
A

akokin

Hi Doug.
Thank you very much for your help but it is not that I want. Sorry. The
result is the table and sort uncorrect. I think would use the array for
selection text:
set arr = Split(Selection.Text, Chr(13))
Next should somehow divide it on 2 part (maybe so UBound (arr)/2) ?) and
take out need lines and join it in correct order: 1 and 31, 2 and 32...30
and 60 etc.

Thank you very much!
 
D

Doug Robbins - Word MVP

It works correctly here as a substitute for what you were trying to do with
the code that you posted.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

avkokin

Hi Doug. Thank you very much. Maybe I simple unable to work with
tables and sort.
I found some other way for my task:
Sub listM()
Dim arr() As String
Dim rng As Range
Dim i As Long

Set rng = Selection.Range
'rng.ListFormat.ConvertNumbersToText
arr = Split(rng, Chr(13))

For i = 0 To UBound(arr) / 2
Debug.Print arr(i) & vbCrLf
Debug.Print arr(i + (UBound(arr) / 2) - 1) & vbCrLf
Next i
End Sub

Your help was much appreciated.
Sincerely, Anton Kokin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top