Sort Excel Ranges in C#
using IronXL;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Select a range
var range = workSheet["A1:D20"];

// Select a column(B)
var column = workSheet.GetColumn(1);

// Sort the range in ascending order (A to Z)
range.SortAscending();

// Sort the range by column(C) in ascending order
range.SortByColumn("C", SortOrder.Ascending);

// Sort the column(B) in descending order (Z to A)
column.SortDescending();

workBook.SaveAs("sortExcelRange.xlsx");
NuGet Download
PM > Install-Package IronXL.Excel
Sort Excel Ranges in C#

Sort Excel Ranges in C#

Arranging data in alphabetical or value order makes human analysis of data feasible in Microsoft Excel. IronXL makes sorting Excel Columns, Rows, and Ranges extremely simple in C# and VB.NET.

Use the SortAscending or SortDescending methods on the selected range or column to apply sorting in the appropriate order. The SortByColumn method, however, requires two parameters: The first input is the column intended to be sorted and the second input is the sorting order.

Learn to Use Named Ranges in Excel with C#
View on GitHub

Ready to Get Started?

Nuget Downloads 2,358,876Version:2026.10just released