IRONSOFTWAREHOME
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");
Imports IronXL

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

' Select a range
Dim range = workSheet("A1:D20")

' Select a column(B)
Dim 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,237,574Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required