Reputation: 149
I am sorting an Excel Sheet which looks like this
This Excel sheet will have other entries like "f7.3.2", "f8.3.1", e.t.c., during the runtime and at the end I would like to sort entire Excel. I am sorting the entire Excel based on Column "B1" as show in the code below
dynamic fullDataRange = xlWorkSheet.UsedRange;
fullDataRange.Sort(fullDataRange.Columns[2], Ex.XlSortOrder.xlAscending);
The output from the above code is
and in the last row you can find
Can anyone please tell me what is that I am doing wrong? I would like to keep the first row as it is and then sort the Excel based on B1 column. I have also tried to freeze the first row before sorting using the below code. It still did not work.
xlWorkSheet.Application.ActiveWindow.SplitRow = 1;
xlWorkSheet.Application.ActiveWindow.FreezePanes = true;
Many thanks in advance.
Upvotes: 1
Views: 1491
Reputation: 149
Okay people I changed the fullDataRange object from dynamic to Excel.Range object and everything works fine! Below is the code
Ex.Range fullDataRange= xlWorkSheet.UsedRange;
fullDataRange.Sort(fullDataRange.Columns[2, miss], Ex.XlSortOrder.xlAscending, miss, miss, Ex.XlSortOrder.xlAscending,
miss, Ex.XlSortOrder.xlAscending, Ex.XlYesNoGuess.xlGuess, miss, miss,
Ex.XlSortOrientation.xlSortColumns, Ex.XlSortMethod.xlPinYin, Ex.XlSortDataOption.xlSortNormal,
Ex.XlSortDataOption.xlSortNormal,
Ex.XlSortDataOption.xlSortNormal);
Thank you @Jeeped for your comment.
Upvotes: 1