Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Asking a question Asking a question is offline
external usenet poster
 
Posts: 1
Default Sorting by dates

One column of my table contains dates, in different forms. Some are
01/01/2002, 01/2002 or just 2002. I understand it may separate these dates,
but suddenly it's not sorting most of the table correctly, with 01/01/2002
and 03/03/2003 in the wrong order and other dates thrown in. How do I fix
this?
  #2   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Sorting by dates

If the dates are in the first column and your table has a header row, the
following macro will sort them correctly:

Dim sortcolumn As Column
Dim i As Long
Dim ddate As Range
With Selection.Tables(1)
Set sortcolumn = .Columns.Add(.Columns(1))
For i = 2 To .Rows.Count
Set ddate = .Cell(i, 2).Range
ddate.End = ddate.End - 1
If Len(ddate.Text) = 4 Then
.Cell(i, 1).Range.Text = "01/01/" & ddate.Text
ElseIf Len(ddate.Text) = 7 Then
.Cell(i, 1).Range.Text = "01/" & ddate.Text
Else
.Cell(i, 1).Range.Text = ddate.Text
End If
Next i
.SortAscending
.Columns(1).Delete
End With


--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.

"Asking a question" Asking a wrote in
message ...
One column of my table contains dates, in different forms. Some are
01/01/2002, 01/2002 or just 2002. I understand it may separate these
dates,
but suddenly it's not sorting most of the table correctly, with 01/01/2002
and 03/03/2003 in the wrong order and other dates thrown in. How do I fix
this?


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
Windows explorer dates to match Word dates John Microsoft Word Help 0 October 17th 05 11:30 PM
Windows explorer dates to match Word dates John Microsoft Word Help 1 October 17th 05 09:26 PM
Windows explorer dates to match Word dates John Microsoft Word Help 1 October 16th 05 10:18 PM
Sorting dates peturpin Tables 5 June 21st 05 08:10 PM
Sorting by Dates Chris Wagner Microsoft Word Help 1 May 13th 05 01:00 AM


All times are GMT +1. The time now is 05:37 PM.

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

About Us

"It's about Microsoft Word"