Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-17-2015, 09:10 AM
omar omar is offline Arrange shortest to longest sentence in Word Windows 7 64bit Arrange shortest to longest sentence in Word Office 2003
Novice
Arrange shortest to longest sentence in Word
 
Join Date: Nov 2015
Posts: 5
omar is on a distinguished road
Default Arrange shortest to longest sentence in Word

Hello,

If I have 100 phrases on top of one another and I need to arrange the shortest phrase on top and longest at the bottom, is there a function in Word to do that?

For eg.

on cloud nine
fool's paradise
cry one's eyes out
grin from ear to ear
like a dog with two tails

Thanks. omar
Reply With Quote
  #2  
Old 11-18-2015, 12:13 AM
macropod's Avatar
macropod macropod is offline Arrange shortest to longest sentence in Word Windows 7 64bit Arrange shortest to longest sentence in Word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

In a word, no. It could be done with a specialised macro though.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-18-2015, 12:35 AM
omar omar is offline Arrange shortest to longest sentence in Word Windows 7 64bit Arrange shortest to longest sentence in Word Office 2003
Novice
Arrange shortest to longest sentence in Word
 
Join Date: Nov 2015
Posts: 5
omar is on a distinguished road
Default

Paul, thank you very much, you don't know how much time I saved by your reply, I was searching for this function in Word. Is there anywhere I can read up about doing a macro on this? I guess I have been using the wrong keyword to search for answers till I find this forum. omar

Quote:
Originally Posted by macropod View Post
In a word, no. It could be done with a specialised macro though.
Reply With Quote
  #4  
Old 11-18-2015, 01:22 AM
macropod's Avatar
macropod macropod is offline Arrange shortest to longest sentence in Word Windows 7 64bit Arrange shortest to longest sentence in Word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could run a macro like the following against a selection of paragraphs:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Tbl As Table, i As Long
With Selection
  Set Tbl = .Range.ConvertToTable
  With Tbl
    .Columns.Add
    For i = 1 To .Rows.Count
      .Cell(i, 2).Range.Text = Len(.Cell(i, 1).Range.Text)
    Next
    .Sort ExcludeHeader:=False, FieldNumber:=2
    .Columns(2).Delete
    .ConvertToText
  End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 11-18-2015, 01:40 AM
omar omar is offline Arrange shortest to longest sentence in Word Windows 7 64bit Arrange shortest to longest sentence in Word Office 2003
Novice
Arrange shortest to longest sentence in Word
 
Join Date: Nov 2015
Posts: 5
omar is on a distinguished road
Default

Good grief, thanks a lot Paul!! Are all the experts playing in this forum?
I have a minor problem, when I run the macro, the results are a little bit out... what do you think I can do to fix this? Results below... omar


BEFORE
alpha bravo charlie
delta echo foxtrot
golf hotel india
juliet kilo lima
mike november oscar
papa quebec romeo
sierra tango uniform
victor whiskey xray
yankee zulu

AFTER
yankee zulu
golf hotel india
juliet kilo lima
papa quebec romeo
delta echo foxtrot
alpha bravo charlie
mike november oscar
victor whiskey xray
sierra tango uniform

Quote:
Originally Posted by macropod View Post
You could run a macro like the following against a selection of paragraphs:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Tbl As Table, i As Long
With Selection
  Set Tbl = .Range.ConvertToTable
  With Tbl
    .Columns.Add
    For i = 1 To .Rows.Count
      .Cell(i, 2).Range.Text = Len(.Cell(i, 1).Range.Text)
    Next
    .Sort ExcludeHeader:=False, FieldNumber:=2
    .Columns(2).Delete
    .ConvertToText
  End With
End With
Application.ScreenUpdating = True
End Sub
Reply With Quote
  #6  
Old 11-18-2015, 04:13 AM
macropod's Avatar
macropod macropod is offline Arrange shortest to longest sentence in Word Windows 7 64bit Arrange shortest to longest sentence in Word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The sort is based on the number of characters on each line. If you change to a fixed-width font you'll see that. Note that some lines also have the same number of characters. If you want to sort on the basis of the string widths on each line, change:
Code:
.Cell(i, 2).Range.Text = Len(.Cell(i, 1).Range.Text)
to:
Code:
.Cell(i, 2).Range.Text = .Cell(i, 1).Range.Characters.Last.Previous.Information(wdHorizontalPositionRelativeToPage)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 11-18-2015, 04:35 AM
omar omar is offline Arrange shortest to longest sentence in Word Windows 7 64bit Arrange shortest to longest sentence in Word Office 2003
Novice
Arrange shortest to longest sentence in Word
 
Join Date: Nov 2015
Posts: 5
omar is on a distinguished road
Default

You made my day Paul, people like you make computer idiots like me live easier. I will try your new Macro and will feedback to you, you have solved 95% of my problems. Thank you very much. omar

Quote:
Originally Posted by macropod View Post
The sort is based on the number of characters on each line. If you change to a fixed-width font you'll see that. Note that some lines also have the same number of characters. If you want to sort on the basis of the string widths on each line, change:
Code:
.Cell(i, 2).Range.Text = Len(.Cell(i, 1).Range.Text)
to:
Code:
.Cell(i, 2).Range.Text = .Cell(i, 1).Range.Characters.Last.Previous.Information(wdHorizontalPositionRelativeToPage)
Reply With Quote
  #8  
Old 11-20-2015, 03:33 PM
omar omar is offline Arrange shortest to longest sentence in Word Windows 7 64bit Arrange shortest to longest sentence in Word Office 2003
Novice
Arrange shortest to longest sentence in Word
 
Join Date: Nov 2015
Posts: 5
omar is on a distinguished road
Default

Paul your skill is amazing, I have spent hours on the wedge organization & your Macro skill has saved my partner over an hour a week for the rest of his life. We are in your debt. Thanks very much. omar

Quote:
Originally Posted by omar View Post
You made my day Paul, people like you make computer idiots like me live easier. I will try your new Macro and will feedback to you, you have solved 95% of my problems. Thank you very much. omar
Reply With Quote
  #9  
Old 11-20-2015, 04:38 PM
macropod's Avatar
macropod macropod is offline Arrange shortest to longest sentence in Word Windows 7 64bit Arrange shortest to longest sentence in Word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You're welcome.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto scheduling issue - longest task first? Project_64 Project 3 01-25-2016 01:14 PM
Arrange shortest to longest sentence in Word Delete does not bring second sentence closer to first sentence Andoheb Word 29 07-03-2014 01:48 PM
Arrange shortest to longest sentence in Word First word of sentence IF and then awolf Word VBA 7 03-16-2014 02:40 PM
Arrange shortest to longest sentence in Word Undo Arrange All in Word nineball Word 1 10-11-2013 12:36 PM
I want to lock a sentence in Word smorkette Word 1 02-06-2010 12:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft