Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Tables / March 2005

Tip: Looking for answers? Try searching our database.

Sorting table on date column

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keenly52 - 30 Mar 2005 03:38 GMT
I have created a macro to sort a table within a protected document. The sort
works fine except on the date column.

All cells in the date column are prepopulated with a date field set to MMMM
d, yyyy; some have dates in them, some are left empty. The sort works fine
except ...

The problem: when sorting "ascending" it sees the "empty" fields as the
earliest dates and places those rows at the top of the table.

Other than placing a fictitioius future date in the empty fields, is there
any way for them to be sorted to the bottom?

Thanks very much for any assistance.

Cheers. Ken.
Greg - 30 Mar 2005 14:21 GMT
Ken,

Well when Word sorts it puts nothing before anything else.  You will
then have to evaluate the column for empty cells between the heading
row and the first date.

Count them then grab the first date and put it in the first empty cell.

Sub ScratchMacro()
Dim oRng As Range
Dim oCell As Cell
Dim oCol As Column
Dim i As Long, j As Long

'Count the empty cells at the top
If Not Selection.Information(wdWithInTable) Then Exit Sub
Set oCol = Selection.Columns(1)
For i = 1 To oCol.Cells.Count - 1 'Use i = 0 for if no header row
If Len(oCol.Cells(i + 1).Range) > 2 Then Exit For
Next i
If i = 0 Then Exit Sub
For j = i + 1 To oCol.Cells.Count
   Set oRng = oCol.Cells(j).Range
   oRng.MoveEnd wdCharacter, -1
   'Use (j -i) if no header row
   oCol.Cells(j - (i - 1)).Range.FormattedText = oRng.FormattedText
   If j > oCol.Cells.Count - i Then oRng.Delete
Next j
End Sub
Keenly52 - 30 Mar 2005 18:39 GMT
Nuttin' before somthin' - seems bass ackwards to me.

Thanks very much for this - haven't tried it yet - when it works you will
have saved me a lot of effort - I literally could not have figured this out
if I spent all day.

Thanks Greg and cheers.
Ken.

> Ken,
>
[quoted text clipped - 25 lines]
> Next j
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.