Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Sort columns of text
I'm using Word 2007 w/XP. I have a table (3 x 10) with columns of text. I
can sort each column individually but can't sort all columns as a single sort. There are no blank columns or rows. What am I missing? Thanks for any help........... Kim |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Sort columns of text
What do you mean? When you sort on a column, all the information in
that row is sorted according to that column. If you just want to have three columns of information, but there's no connection between items in a row, then you don't want to use a table, you want to simply type lists. You could copy each column and paste it to a new table, sort it, and then paste it into the original table? On Jan 8, 11:53*am, Kim wrote: I'm using Word 2007 w/XP. *I have a table (3 x 10) with columns of text.. *I can sort each column individually but can't sort all columns as a single sort. *There are no blank columns or rows. What am I missing? Thanks for any help........... Kim |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Sort columns of text
Kim,
Apparently missing is a complete understanding of what exactly you are trying to do. If (big if) you want to sort the contents of column 1 through 3 as one continous sorted string top to bottom left to right through the table then the process suggested by Mr. Daniels can be automated with a macro as follows: Option Explicit Dim pCell1 As Word.Cell Dim pCell2 As Word.Cell Sub TableSorter() Dim SourceTable As Table Dim i As Long, j As Long, k As Long Dim pTmpDoc As Word.Document Dim pTmpTable As Table Dim oRng As Word.Range On Error GoTo Err_Handler Set SourceTable = Selection.Tables(1) i = SourceTable.Range.Cells.Count 'Create a temporary document and insert a 1 column/multi-row table Set pTmpDoc = Documents.Add(Visible:=False) Set pTmpTable = pTmpDoc.Tables.Add(pTmpDoc.Content, i, 1) 'Fill oTmpTable with contents of the table to be sorted TableFillAndRefill SourceTable, pTmpTable 'Sort the temporary table pTmpTable.Sort 'Redefine source table contents based on sort With SourceTable For i = 1 To .Range.Columns.Count For j = 1 To .Range.Rows.Count k = k + 1 Set oRng = pTmpTable.Cell(k, 1).Range .Cell(j, i).Range.Text = Left(oRng.Text, Len(oRng.Text) - 2) Next j Next i End With 'Clean up. Set oRng = Nothing pTmpDoc.Close SaveChanges:=False Exit Sub Err_Handler: If Err.Number = 5941 Then MsgBox "The cursor must be positioned in the table you want to sort." _ & vbCr & vbCr & " Position the cursor and run this procedure again." End If End Sub Sub TableFillAndRefill(pTable1 As Table, pTable2 As Table) Dim pCell1 As Word.Cell Dim pCell2 As Word.Cell Set pCell1 = pTable1.Cell(1, 1) Set pCell2 = pTable2.Cell(1, 1) Do pCell2.Range = Left$(pCell1.Range, Len(pCell1.Range) - 2) Set pCell1 = pCell1.Next Set pCell2 = pCell2.Next Loop Until pCell1 Is Nothing End Sub On Jan 8, 11:53*am, Kim wrote: I'm using Word 2007 w/XP. *I have a table (3 x 10) with columns of text.. *I can sort each column individually but can't sort all columns as a single sort. *There are no blank columns or rows. What am I missing? Thanks for any help........... Kim |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Sort columns of text
On Jan 8, 5:14*pm, Greg Maxey wrote:
Kim, Apparently missing is a complete understanding of what exactly you are trying to do. *If (big if) you want to sort the contents of column 1 through 3 as one continous sorted string top to bottom left to right through the table Seems like a good guess. Could you do it with Convert Table to Text (choosing Return as the separator), then just Sort the result? then the process suggested by Mr. Daniels can be automated with a macro as follows: Option Explicit Dim pCell1 As Word.Cell Dim pCell2 As Word.Cell Sub TableSorter() Dim SourceTable As Table Dim i As Long, j As Long, k As Long Dim pTmpDoc As Word.Document Dim pTmpTable As Table Dim oRng As Word.Range On Error GoTo Err_Handler Set SourceTable = Selection.Tables(1) i = SourceTable.Range.Cells.Count 'Create a temporary document and insert a 1 column/multi-row table Set pTmpDoc = Documents.Add(Visible:=False) Set pTmpTable = pTmpDoc.Tables.Add(pTmpDoc.Content, i, 1) 'Fill oTmpTable with contents of the table to be sorted TableFillAndRefill SourceTable, pTmpTable 'Sort the temporary table pTmpTable.Sort 'Redefine source table contents based on sort With SourceTable * For i = 1 To .Range.Columns.Count * * For j = 1 To .Range.Rows.Count * * * k = k + 1 * * * Set oRng = pTmpTable.Cell(k, 1).Range * * * .Cell(j, i).Range.Text = Left(oRng.Text, Len(oRng.Text) - 2) * * Next j * Next i End With 'Clean up. Set oRng = Nothing pTmpDoc.Close SaveChanges:=False Exit Sub Err_Handler: If Err.Number = 5941 Then * MsgBox "The cursor must be positioned in the table you want to sort." _ * * * * *& vbCr & vbCr & " Position the cursor and run this procedure again." End If End Sub Sub TableFillAndRefill(pTable1 As Table, pTable2 As Table) Dim pCell1 As Word.Cell Dim pCell2 As Word.Cell Set pCell1 = pTable1.Cell(1, 1) Set pCell2 = pTable2.Cell(1, 1) Do * pCell2.Range = Left$(pCell1.Range, Len(pCell1.Range) - 2) * Set pCell1 = pCell1.Next * Set pCell2 = pCell2.Next Loop Until pCell1 Is Nothing End Sub On Jan 8, 11:53*am, Kim wrote: I'm using Word 2007 w/XP. *I have a table (3 x 10) with columns of text. *I can sort each column individually but can't sort all columns as a single sort. *There are no blank columns or rows. What am I missing? Thanks for any help........... Kim- |
#5
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Sort columns of text
Do you mean using a macro? Sure, but it would leave a sinlge sorted
list of paragraphs. I simply don't know what output the OP wants. Sub ScratchMaco() With Selection .Tables(1).ConvertToText Separator:=wdSeparateByParagraphs .Sort .Paragraphs(1).Range.Delete Selection.ConvertToTable wdSeparateByParagraphs, 2, 3 End With End Sub The reason the other macro looks more complex is if you would try to put the resulting output of the code above back in a table is would be sorted left to right top to bottom. On Jan 8, 8:59*pm, "Peter T. Daniels" wrote: On Jan 8, 5:14*pm, Greg Maxey wrote: Kim, Apparently missing is a complete understanding of what exactly you are trying to do. *If (big if) you want to sort the contents of column 1 through 3 as one continous sorted string top to bottom left to right through the table Seems like a good guess. Could you do it with Convert Table to Text (choosing Return as the separator), then just Sort the result? then the process suggested by Mr. Daniels can be automated with a macro as follows: Option Explicit Dim pCell1 As Word.Cell Dim pCell2 As Word.Cell Sub TableSorter() Dim SourceTable As Table Dim i As Long, j As Long, k As Long Dim pTmpDoc As Word.Document Dim pTmpTable As Table Dim oRng As Word.Range On Error GoTo Err_Handler Set SourceTable = Selection.Tables(1) i = SourceTable.Range.Cells.Count 'Create a temporary document and insert a 1 column/multi-row table Set pTmpDoc = Documents.Add(Visible:=False) Set pTmpTable = pTmpDoc.Tables.Add(pTmpDoc.Content, i, 1) 'Fill oTmpTable with contents of the table to be sorted TableFillAndRefill SourceTable, pTmpTable 'Sort the temporary table pTmpTable.Sort 'Redefine source table contents based on sort With SourceTable * For i = 1 To .Range.Columns.Count * * For j = 1 To .Range.Rows.Count * * * k = k + 1 * * * Set oRng = pTmpTable.Cell(k, 1).Range * * * .Cell(j, i).Range.Text = Left(oRng.Text, Len(oRng.Text) - 2) * * Next j * Next i End With 'Clean up. Set oRng = Nothing pTmpDoc.Close SaveChanges:=False Exit Sub Err_Handler: If Err.Number = 5941 Then * MsgBox "The cursor must be positioned in the table you want to sort." _ * * * * *& vbCr & vbCr & " Position the cursor and run this procedure again." End If End Sub Sub TableFillAndRefill(pTable1 As Table, pTable2 As Table) Dim pCell1 As Word.Cell Dim pCell2 As Word.Cell Set pCell1 = pTable1.Cell(1, 1) Set pCell2 = pTable2.Cell(1, 1) Do * pCell2.Range = Left$(pCell1.Range, Len(pCell1.Range) - 2) * Set pCell1 = pCell1.Next * Set pCell2 = pCell2.Next Loop Until pCell1 Is Nothing End Sub On Jan 8, 11:53*am, Kim wrote: I'm using Word 2007 w/XP. *I have a table (3 x 10) with columns of text. *I can sort each column individually but can't sort all columns as a single sort. *There are no blank columns or rows. What am I missing? Thanks for any help........... Kim-- Hide quoted text - - Show quoted text - |
#6
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Sort columns of text
Sorry, last macro posted was an attempt to combine the two below and
wouldn't work. Sorts leaving a single sorted lists Sub ScratchMaco() With Selection .Tables(1).ConvertToText Separator:=wdSeparateByParagraphs .Sort .Paragraphs(1).Range.Delete End With End Sub Sorts and returns list to table format sorted left to right/top to bottom. Sub ScratchMacoII() With Selection .Tables(1).ConvertToText Separator:=wdSeparateByParagraphs .Sort .MoveStart wdLine, 1 Selection.ConvertToTable wdSeparateByParagraphs, , 3 End With End Sub Peter T. Daniels wrote: On Jan 8, 5:14 pm, Greg Maxey wrote: Kim, Apparently missing is a complete understanding of what exactly you are trying to do. If (big if) you want to sort the contents of column 1 through 3 as one continous sorted string top to bottom left to right through the table Seems like a good guess. Could you do it with Convert Table to Text (choosing Return as the separator), then just Sort the result? then the process suggested by Mr. Daniels can be automated with a macro as follows: Option Explicit Dim pCell1 As Word.Cell Dim pCell2 As Word.Cell Sub TableSorter() Dim SourceTable As Table Dim i As Long, j As Long, k As Long Dim pTmpDoc As Word.Document Dim pTmpTable As Table Dim oRng As Word.Range On Error GoTo Err_Handler Set SourceTable = Selection.Tables(1) i = SourceTable.Range.Cells.Count 'Create a temporary document and insert a 1 column/multi-row table Set pTmpDoc = Documents.Add(Visible:=False) Set pTmpTable = pTmpDoc.Tables.Add(pTmpDoc.Content, i, 1) 'Fill oTmpTable with contents of the table to be sorted TableFillAndRefill SourceTable, pTmpTable 'Sort the temporary table pTmpTable.Sort 'Redefine source table contents based on sort With SourceTable For i = 1 To .Range.Columns.Count For j = 1 To .Range.Rows.Count k = k + 1 Set oRng = pTmpTable.Cell(k, 1).Range .Cell(j, i).Range.Text = Left(oRng.Text, Len(oRng.Text) - 2) Next j Next i End With 'Clean up. Set oRng = Nothing pTmpDoc.Close SaveChanges:=False Exit Sub Err_Handler: If Err.Number = 5941 Then MsgBox "The cursor must be positioned in the table you want to sort." _ & vbCr & vbCr & " Position the cursor and run this procedure again." End If End Sub Sub TableFillAndRefill(pTable1 As Table, pTable2 As Table) Dim pCell1 As Word.Cell Dim pCell2 As Word.Cell Set pCell1 = pTable1.Cell(1, 1) Set pCell2 = pTable2.Cell(1, 1) Do pCell2.Range = Left$(pCell1.Range, Len(pCell1.Range) - 2) Set pCell1 = pCell1.Next Set pCell2 = pCell2.Next Loop Until pCell1 Is Nothing End Sub On Jan 8, 11:53 am, Kim wrote: I'm using Word 2007 w/XP. I have a table (3 x 10) with columns of text. I can sort each column individually but can't sort all columns as a single sort. There are no blank columns or rows. What am I missing? Thanks for any help........... Kim- |
#7
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Sort columns of text
Your guess was that Kim wanted a single sorted list of paragraphs --
so unless Kim has lots of such tables, it's more trouble installing the macro than doing the two steps to sort all the items in the table. On Jan 8, 9:27*pm, Greg Maxey wrote: Do you mean using a macro? *Sure, but it would leave a sinlge sorted list of paragraphs. *I simply don't know what output the OP wants. Sub ScratchMaco() With Selection * .Tables(1).ConvertToText Separator:=wdSeparateByParagraphs * .Sort * .Paragraphs(1).Range.Delete * Selection.ConvertToTable wdSeparateByParagraphs, 2, 3 End With End Sub The reason the other macro looks more complex is if you would try to put the resulting output of the code above back in a table is would be sorted left to right top to bottom. On Jan 8, 8:59*pm, "Peter T. Daniels" wrote: On Jan 8, 5:14*pm, Greg Maxey wrote: Kim, Apparently missing is a complete understanding of what exactly you are trying to do. *If (big if) you want to sort the contents of column 1 through 3 as one continous sorted string top to bottom left to right through the table Seems like a good guess. Could you do it with Convert Table to Text (choosing Return as the separator), then just Sort the result? then the process suggested by Mr. Daniels can be automated with a macro as follows: Option Explicit Dim pCell1 As Word.Cell Dim pCell2 As Word.Cell Sub TableSorter() Dim SourceTable As Table Dim i As Long, j As Long, k As Long Dim pTmpDoc As Word.Document Dim pTmpTable As Table Dim oRng As Word.Range On Error GoTo Err_Handler Set SourceTable = Selection.Tables(1) i = SourceTable.Range.Cells.Count 'Create a temporary document and insert a 1 column/multi-row table Set pTmpDoc = Documents.Add(Visible:=False) Set pTmpTable = pTmpDoc.Tables.Add(pTmpDoc.Content, i, 1) 'Fill oTmpTable with contents of the table to be sorted TableFillAndRefill SourceTable, pTmpTable 'Sort the temporary table pTmpTable.Sort 'Redefine source table contents based on sort With SourceTable * For i = 1 To .Range.Columns.Count * * For j = 1 To .Range.Rows.Count * * * k = k + 1 * * * Set oRng = pTmpTable.Cell(k, 1).Range * * * .Cell(j, i).Range.Text = Left(oRng.Text, Len(oRng.Text) - 2) * * Next j * Next i End With 'Clean up. Set oRng = Nothing pTmpDoc.Close SaveChanges:=False Exit Sub Err_Handler: If Err.Number = 5941 Then * MsgBox "The cursor must be positioned in the table you want to sort." _ * * * * *& vbCr & vbCr & " Position the cursor and run this procedure again." End If End Sub Sub TableFillAndRefill(pTable1 As Table, pTable2 As Table) Dim pCell1 As Word.Cell Dim pCell2 As Word.Cell Set pCell1 = pTable1.Cell(1, 1) Set pCell2 = pTable2.Cell(1, 1) Do * pCell2.Range = Left$(pCell1.Range, Len(pCell1.Range) - 2) * Set pCell1 = pCell1.Next * Set pCell2 = pCell2.Next Loop Until pCell1 Is Nothing End Sub On Jan 8, 11:53*am, Kim wrote: I'm using Word 2007 w/XP. *I have a table (3 x 10) with columns of text. *I can sort each column individually but can't sort all columns as a single sort. *There are no blank columns or rows. What am I missing? Thanks for any help........... Kim-- |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Can you sort a list when using the columns feature in word? | Page Layout | |||
How to sort multiple columns in a table ascending text? | Tables | |||
Word datasource sort doesn't sort all records in mail merge | Mailmerge | |||
Table Sort - Sort only 3 of 4 columns | Microsoft Word Help | |||
Sort whole document prepared in columns not single pages | Microsoft Word Help |