Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cannot sort Tables in C#

I am having problems sorting Tables in Excel 2007 using C#. The below method
changes the cursor to ascending in the Table's header sort fields but fails
to sort the cells. Under debugger the SortField and Table ranges passed to
Excel look OK and Apply() executes without errors. Any help will be
appreciated.

Thanks,
Andrew

/// <summary
/// Sort Table in ascending order by the specified keys
/// </summary
/// <param name="inTable"input Table to sort</param
/// <param name="inColumns"input key column names to use</param
public static void SortTableByKeys(Excel.ListObject inTable, string[]
inColumns)
{
inTable.Sort.SortFields.Clear();
foreach (string column in inColumns)
{
inTable.Sort.SortFields.Add(inTable.ListColumns.ge t_Item(column).Range,
Excel.XlSortType.xlSortValues, Excel.XlSortOrder.xlAscending, Type.Missing,
Excel.XlSortDataOption.xlSortNormal);
}
inTable.Sort.SetRange(inTable.Range);
inTable.Sort.Orientation = Excel.XlSortOrientation.xlSortColumns;
inTable.Sort.MatchCase = false;
inTable.Sort.Header = Excel.XlYesNoGuess.xlYes;
inTable.Sort.SortMethod = Excel.XlSortMethod.xlPinYin;
inTable.Sort.Apply();
}

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
match and sort two different tables yowzers Excel Worksheet Functions 2 February 3rd 10 10:47 PM
Script to sort tables Jeremy Excel Discussion (Misc queries) 1 October 30th 09 02:23 PM
Sort two tables of data AMH Excel Worksheet Functions 5 May 14th 09 01:51 PM
sort tables KJR Excel Worksheet Functions 1 October 3rd 06 10:10 PM
Automatically Sort Tables tamato43 Excel Discussion (Misc queries) 2 March 22nd 05 07:59 PM


All times are GMT +1. The time now is 11:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"