Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-18-2014, 01:06 PM
Cosmo Cosmo is offline Sorting part of a table Windows Vista Sorting part of a table Office 2007
Competent Performer
Sorting part of a table
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default Sorting part of a table

I need to sort a table, but leave the first 2 rows out of the sort (the first row is a general header, the second is a column header)



The table's sort method appears to only allow excluding a single header row, so I am sorting using a selection:

Code:
Dim rng As Range
Dim ct As Integer
With tbl
    ct = .Rows.Count
    If (ct > 2) Then
        Set rng = .Rows(3).Range
        rng.End = .Rows(ct).Range.End
        rng.Select
        Call Selection.Sort(ExcludeHeader:=False, FieldNumber:=1, SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending) 
    End If
End With
Is this the best/only way to do this? I would prefer not using a selection, if that is possible.
Reply With Quote
  #2  
Old 06-18-2014, 04:08 PM
macropod's Avatar
macropod macropod is offline Sorting part of a table Windows 7 32bit Sorting part of a table Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

This works for me:
Code:
Sub Demo()
Dim Rng As Range
With ActiveDocument.Tables(1)
  Set Rng = .Range
  With Rng
    .Start = .Rows(3).Range.Start
    .Sort
  End With
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-19-2014, 10:40 AM
Cosmo Cosmo is offline Sorting part of a table Windows Vista Sorting part of a table Office 2007
Competent Performer
Sorting part of a table
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
This works for me:
Code:
Sub Demo()
Dim Rng As Range
With ActiveDocument.Tables(1)
  Set Rng = .Range
  With Rng
    .Start = .Rows(3).Range.Start
    .Sort
  End With
End With
End Sub
Thanks, that looks good to me!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting part of a table Sorting a Word table containing cross-references mpdsal Word Tables 5 02-13-2013 06:44 PM
Sorting part of a table Sorting Challenge gbaker Excel Programming 11 06-22-2012 09:39 AM
Sorting by certain criteria randenius Excel 2 06-11-2012 02:18 AM
Sorting part of a table Need help in aplhabetica sorting brooklyn86 Word VBA 1 06-05-2012 11:43 AM
Show part codes only whose have Book qty bal.in Pivot table PRADEEPB270 Excel 2 02-15-2012 04:09 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:55 AM.


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