Reply
 
Thread Tools Display Modes
  #1   Report Post  
sdlfkj
 
Posts: n/a
Default Possible to reverse line order?

I have lines of numbers that I need to reverse.

So instead of
3rd line
2nd line
1st line

I need it to read
1st line
2nd line
3rd line

I just want to highlight the 3 lines and click something to reverse the order instead of cutting and pasting hundreds of times. Any
suggestions?


  #2   Report Post  
Greg Maxey
 
Posts: n/a
Default

I suspect that there is a far superior method, but I cobbled the following
together that seems to work. Select the three lines and run this macro:

Sub ReverseLineOrder()
Dim myRng As Range
Dim tmpString1 As String
Dim tmpString2 As String
Dim tmpString3 As String

Set myRng = Selection.Range
tmpString1 = myRng.Paragraphs(3).Range
tmpString2 = myRng.Paragraphs(2).Range
tmpString3 = myRng.Paragraphs(1).Range
myRng.Delete
myRng.Text = tmpString1 & tmpString2 & tmpString3
End Sub

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

sdlfkj wrote:
I have lines of numbers that I need to reverse.

So instead of
3rd line
2nd line
1st line

I need it to read
1st line
2nd line
3rd line

I just want to highlight the 3 lines and click something to reverse
the order instead of cutting and pasting hundreds of times. Any
suggestions?



  #3   Report Post  
Greg Maxey
 
Posts: n/a
Default

OK maybe this is a little better. Will do anynumber of lines provided each
line is an individual paragraph.

Sub ReverseLineOrder()
Dim myRng As Range
Dim tmpString
Dim i As Integer

Set myRng = Selection.Range
For i = myRng.Paragraphs.Count To 1 Step -1
tmpString = tmpString & myRng.Paragraphs(i).Range
Next i
myRng.Text = tmpString
End Sub

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

sdlfkj wrote:
I have lines of numbers that I need to reverse.

So instead of
3rd line
2nd line
1st line

I need it to read
1st line
2nd line
3rd line

I just want to highlight the 3 lines and click something to reverse
the order instead of cutting and pasting hundreds of times. Any
suggestions?



  #4   Report Post  
Greg Maxey
 
Posts: n/a
Default

A little more general and corrects the addition of a blank paragraph if
myRng.end is the same as activedocument.end

Sub ReverseParagraphOrder()
'Created 04/20/2005 by Greg Maxey
'Reverses the order of a group of selected paragraphs
Dim myRng As Range
Dim tmpString
Dim i As Integer

Set myRng = Selection.Range
For i = myRng.Paragraphs.Count To 1 Step -1
tmpString = tmpString & myRng.Paragraphs(i).Range
Next i
If myRng.End = ActiveDocument.Range.End Then
myRng.Text = Left(tmpString, Len(tmpString) - 1)
Else
myRng.Text = tmpString
End If
End Sub

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

sdlfkj wrote:
I have lines of numbers that I need to reverse.

So instead of
3rd line
2nd line
1st line

I need it to read
1st line
2nd line
3rd line

I just want to highlight the 3 lines and click something to reverse
the order instead of cutting and pasting hundreds of times. Any
suggestions?



  #5   Report Post  
Luc
 
Posts: n/a
Default

Greg,
Just taking some time to thank you for your valuable contibutions in the
newsgroup. This is a typical example of a time and money saver.
This is also why we keep coming back to this newsgroup to find answers you
will not find easily somewhere else.
Thanks again Greg!
Luc
"Greg Maxey" schreef in bericht
...
A little more general and corrects the addition of a blank paragraph if
myRng.end is the same as activedocument.end

Sub ReverseParagraphOrder()
'Created 04/20/2005 by Greg Maxey
'Reverses the order of a group of selected paragraphs
Dim myRng As Range
Dim tmpString
Dim i As Integer

Set myRng = Selection.Range
For i = myRng.Paragraphs.Count To 1 Step -1
tmpString = tmpString & myRng.Paragraphs(i).Range
Next i
If myRng.End = ActiveDocument.Range.End Then
myRng.Text = Left(tmpString, Len(tmpString) - 1)
Else
myRng.Text = tmpString
End If
End Sub

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

sdlfkj wrote:
I have lines of numbers that I need to reverse.

So instead of
3rd line
2nd line
1st line

I need it to read
1st line
2nd line
3rd line

I just want to highlight the 3 lines and click something to reverse
the order instead of cutting and pasting hundreds of times. Any
suggestions?







  #6   Report Post  
Greg Maxey
 
Posts: n/a
Default

Luc,

Thanks for the feedback.

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Luc wrote:
Greg,
Just taking some time to thank you for your valuable contibutions in
the newsgroup. This is a typical example of a time and money saver.
This is also why we keep coming back to this newsgroup to find
answers you will not find easily somewhere else.
Thanks again Greg!
Luc
"Greg Maxey" schreef in bericht
...
A little more general and corrects the addition of a blank paragraph
if myRng.end is the same as activedocument.end

Sub ReverseParagraphOrder()
'Created 04/20/2005 by Greg Maxey
'Reverses the order of a group of selected paragraphs
Dim myRng As Range
Dim tmpString
Dim i As Integer

Set myRng = Selection.Range
For i = myRng.Paragraphs.Count To 1 Step -1
tmpString = tmpString & myRng.Paragraphs(i).Range
Next i
If myRng.End = ActiveDocument.Range.End Then
myRng.Text = Left(tmpString, Len(tmpString) - 1)
Else
myRng.Text = tmpString
End If
End Sub

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

sdlfkj wrote:
I have lines of numbers that I need to reverse.

So instead of
3rd line
2nd line
1st line

I need it to read
1st line
2nd line
3rd line

I just want to highlight the 3 lines and click something to reverse
the order instead of cutting and pasting hundreds of times. Any
suggestions?



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to reverse the order of pages in word 2000 labhih Microsoft Word Help 1 April 17th 05 08:04 PM
Manual duplex printing and reversing print order on reverse side Shaun Microsoft Word Help 0 April 11th 05 11:05 AM
printing reverse order Ruth Messing Microsoft Word Help 1 March 16th 05 11:53 PM
My docs are saved in reverse alphabet order, how do I fix it? ppistol13 Microsoft Word Help 1 February 28th 05 07:06 PM
Vertical line--leaving line and losing the box Chad Harris New Users 1 February 1st 05 05:50 AM


All times are GMT +1. The time now is 09:40 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"