Desktop User Guides > Professional > Table scripting > Table presentation > Sorting tables > Sorting grid tables
Sorting grid tables
Sample script file: SortedTables.mrs
This example script is based on the Museum sample data set. See Running the sample table scripts for more information.
You can sort the columns and rows of a grid table. For example, using the Museum Rating grid table shown in Creating a grid table, we can sort the rows on one of the columns (which are formed from the categories of the variable inside the grid) and we can sort the columns on one of the rows (which are formed from the iterations). Here is the code:
With TableDoc.Tables
  .AddNewGrid("SortedRatingGrid", "rating", , "Rating grid - sorted")
  ' Sort on one of the rating categories
  .SortedRatingGrid.SortColumn = "rating[..].Column{Very_interested_5}"
  .AddNewGrid("SortedRatingGrid2", "rating", , "Rating grid - sorted #2")
  ' Sort on the iterations
  .SortedRatingGrid2.SortRow = "rating{Dinosaurs}"
End With
Here is the first table in which the rows are sorted on the Very interested column:
This graphic is described in the surrounding text.
Here is the second table in which the columns are sorted on the Dinosaurs row:
This graphic is described in the surrounding text.
Note that you do not normally sort a grid table on the base row or column. See The base in grid tables.
See also
Sorting tables