Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Excel has been one of the most popular forms of data manipulation for many years, with millions of computer users employing this spreadsheet every day for work or personal accounting needs. It is available for over 1.4 billion Windows-based PCs, which translates to about 45% of the world's population. Excel is a powerful tool for data analysis, back-and-forth editing, sorting, filtering, pivot tables, and charts. It is also one of the most popular tools in the business world with over four million people actively using it every day. Column and row headers, column letters, and row numbers are principal features of Excel spreadsheets. Using column letters and row numbers, you can address any cell — the main element in Excel.
The popularity of Excel among businesses has created an environment where there are several expensive editions to choose from that offer more features and financial analysis, including the "Professional" edition. This version of Excel is typically used in business settings where the functionality enables higher levels of data analysis, advanced graphing capabilities, and coordination with third-party applications. Excel is a spreadsheet program with a Microsoft Word-like interface that allows users to create and analyze data using formulas.
Let's take a look at how we can move rows or columns in Excel.
We can move rows or selected cells in Microsoft Excel. There are several methods to do this. Let's suppose we have these rows in Microsoft Excel and that we need to move a row. We can now examine how to get this done.
Original data rows in Excel
Follow the following steps to move the row:
Moving data using drag and drop
These steps can be followed for selected cells too. If you want to move the entire column, you can select the entire column and then follow the same steps.
The cut-and-paste method is an easy method for moving rows and columns. You can do it without the drag-and-drop method, and without inserting a new row or new column. Follow the steps to move an entire row or multiple adjacent rows in Excel.
Cutting the selected row
Pasting a row from the right-click menu
The result after the cut-and-paste method
Using this method, it becomes very easy to move entire rows or columns in Excel. You can move columns too by following the same technique. Simply select columns and all operations will be performed on the selected column.
IronXL is a .NET C# Excel Library for developers to edit and save Excel files. It has been designed to help developers quickly create, edit, and save Excel files without the need for Microsoft Excel to be installed.
The IronXL Excel library has been designed for .NET C# developers to edit and save Excel files without having Microsoft Excel installed on their machines. The IronXL Excel library is a powerful tool that can be used by any developer who needs to work with Excel spreadsheets in their projects. The IronXL Library includes many features that are not found in the standard Microsoft Excel libraries. These include:
Here is the code to add a row at the first position in the Excel file:
using IronXL;
static void Main(string [] args)
{
WorkBook wb = WorkBook.Load("sample.xlsx");
WorkSheet ws = wb.GetWorkSheet("Sheet1");
int j = ws.Rows.Count() + 1;
for (int i = 1; i <= ws.Rows.Count(); i++)
{
if (j == 0)
{
ws.Rows [0].Value = "new row";
break;
};
ws ["A" + (j + 1)].Value = ws ["A" + j].Value;
ws ["B" + (j + 1)].Value = ws ["B" + j].Value;
ws ["C" + (j + 1)].Value = ws ["C" + j].Value;
ws ["D" + (j + 1)].Value = ws ["D" + j].Value;
ws ["E" + (j + 1)].Value = ws ["E" + j].Value;
j = j - 1;
}
wb.SaveAs("sample.xlsx");
}
using IronXL;
static void Main(string [] args)
{
WorkBook wb = WorkBook.Load("sample.xlsx");
WorkSheet ws = wb.GetWorkSheet("Sheet1");
int j = ws.Rows.Count() + 1;
for (int i = 1; i <= ws.Rows.Count(); i++)
{
if (j == 0)
{
ws.Rows [0].Value = "new row";
break;
};
ws ["A" + (j + 1)].Value = ws ["A" + j].Value;
ws ["B" + (j + 1)].Value = ws ["B" + j].Value;
ws ["C" + (j + 1)].Value = ws ["C" + j].Value;
ws ["D" + (j + 1)].Value = ws ["D" + j].Value;
ws ["E" + (j + 1)].Value = ws ["E" + j].Value;
j = j - 1;
}
wb.SaveAs("sample.xlsx");
}
Imports IronXL
Shared Sub Main(ByVal args() As String)
Dim wb As WorkBook = WorkBook.Load("sample.xlsx")
Dim ws As WorkSheet = wb.GetWorkSheet("Sheet1")
Dim j As Integer = ws.Rows.Count() + 1
For i As Integer = 1 To ws.Rows.Count()
If j = 0 Then
ws.Rows (0).Value = "new row"
Exit For
End If
ws ("A" & (j + 1)).Value = ws ("A" & j).Value
ws ("B" & (j + 1)).Value = ws ("B" & j).Value
ws ("C" & (j + 1)).Value = ws ("C" & j).Value
ws ("D" & (j + 1)).Value = ws ("D" & j).Value
ws ("E" & (j + 1)).Value = ws ("E" & j).Value
j = j - 1
Next i
wb.SaveAs("sample.xlsx")
End Sub
It will move the rows down and a new row will be placed at the first position of the document. for
loop will be moving all rows down and adding the new row data at the first position. We can add the rows at the end of the document too. Let's take a look at how we can do it:
using IronXL;
static void Main(string [] args)
{
WorkBook wb = WorkBook.Load("sample.xlsx");
WorkSheet ws = wb.GetWorkSheet("Sheet1");
int i = ws.Rows.Count() + 1;
ws ["A" + i].Value = "New Row";
ws ["B" + i].Value = "New Row";
ws ["C" + i].Value = "New Row";
ws ["D" + i].Value = "New Row";
ws ["E" + i].Value = "New Row";
wb.SaveAs("sample.xlsx");
}
using IronXL;
static void Main(string [] args)
{
WorkBook wb = WorkBook.Load("sample.xlsx");
WorkSheet ws = wb.GetWorkSheet("Sheet1");
int i = ws.Rows.Count() + 1;
ws ["A" + i].Value = "New Row";
ws ["B" + i].Value = "New Row";
ws ["C" + i].Value = "New Row";
ws ["D" + i].Value = "New Row";
ws ["E" + i].Value = "New Row";
wb.SaveAs("sample.xlsx");
}
Imports IronXL
Shared Sub Main(ByVal args() As String)
Dim wb As WorkBook = WorkBook.Load("sample.xlsx")
Dim ws As WorkSheet = wb.GetWorkSheet("Sheet1")
Dim i As Integer = ws.Rows.Count() + 1
ws ("A" & i).Value = "New Row"
ws ("B" & i).Value = "New Row"
ws ("C" & i).Value = "New Row"
ws ("D" & i).Value = "New Row"
ws ("E" & i).Value = "New Row"
wb.SaveAs("sample.xlsx")
End Sub
This given piece of code will add the rows at the bottom of the document. You can see more details on how to add a new row in our how-to pages.
IronXL has a variety of pricing plans. You can even get a free trial — the IronXL free trial can be activated without any payment or card information. However, IronXL is free for development. Visit our licensing page for more information.
9 .NET API products for your office documents