Reversing word order - is it possible?

B

Bert Coules

Is there a way (apart from doing it manually, of course) of reversing the
word order of a block of text? So that, for example, "This sentence is
normal" becomes "normal is sentence this"?

Easy enough to do for four words, but (for reasons far too unbelievable to
go into) I have to reverse several chunks of text running to a hundred words
or so each.

Many thanks,

Bert
www.bertcoules.co.uk
 
G

Greg Maxey

Bert,

There are probably better ways, but this seems to do the basic job.

Select the sentence (minus the final punctuation) and run this macro:

Sub RevOrder()
Dim i As Long
Dim myArray() As String
Dim myStr As String
myArray = Split(Selection.Text, " ")
For i = UBound(myArray) To 0 Step -1
myStr = myStr + " " & myArray(i)
Next i
myStr = Trim(myStr)
Selection.Delete
Selection.InsertAfter myStr
End Sub
 

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