Thread: Sort Question
View Single Post
  #5   Report Post  
RFJ
 
Posts: n/a
Default

Thanks Jay (particularly for the fast response) - its working now with that
extra line BG

Interestingly, if there is an empty cell in column 2 (the one I'm sorting
on), the sort defaults to column 1. But that was a problem easily overcome
by putting a single dash in the cell.

Regards

Rob



"Jay Freedman" wrote in message
...
Hi Rob,

Now I see what's probably happening. Do you have one or more rows where
there's only one line in the cell in Column 2? That will cause that error
message (oddly, having an empty cell isn't any problem).

The fix is simple. Add the line "On Error Resume Next" to the macro as

shown
in the segment below:

For Each oRow In Selection.Tables(1).Rows
' sort the contents of the cell in column 2
On Error Resume Next
Set oRg = oRow.Cells(2).Range
oRg.MoveEnd wdCharacter, -1
oRg.Sort
Next oRow
End Sub

That will make the macro ignore any cells it can't sort.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

RFJ wrote:
Hi Jay,

Tx for the response - sorry about the delay (been away)

I've got the macro installed but an error message is being generated
as follows

Runtime error "5280"
Word found no valid records to sort

Debug is highlighting the line oRg.Sort

My position on the macro learning curve is almost at the bottom so
I'm stuck as to what to do next. All I know is :
- a table is /definitely/ there
- I want to sort on Column 2 so have changed the code accordingly.

Any further help would be much appreciated.

Rob


"Jay Freedman" wrote in message
...
Hi Rob,

First, make sure that there's a paragraph mark (not a manual line
break) at


cut