In this article, we will learn how to select Excel range in
- VBA (i.e. Visual Basic for Applications)
- C#.NET using Aspose.Cells for .NET
- Java using Aspose.Cells for Java
Select Excel Range in VBA
The following sample code selects the Excel range in VBA. In order to select Excel range, you need to specify the range in string format.
'Select Excel range C4:G8 in worksheet. Application.ActiveSheet.Range("C4:G8").Select
After the execution of this code, the range will be selected as shown in this image.
Select Excel Range in C#.NET
You can also select the Excel range in C#.NET using the Aspose.Cells for .NET API with the following code. The code selects the range D6:G9 using the Worksheet.SelectRange() method which requires parameters specifying the start row, start column, total number of rows and total number of columns.
//Select Excel Cell Range i.e. D6:G9. int startRow = 5; int startColumn = 3; int totalRows = 4; int totalColumns = 4; //Select Excel cell range with the specified parameters. workbook.Worksheets[0].SelectRange(startRow, startColumn, totalRows, totalColumns, true);
After the execution of this code, the range will be selected as shown in this image.
Select Excel Range in Java
Similarly, you can also select the Excel range in Java using the Aspose.Cells for Java API with the following code. The code selects the range C4:F7 using the Worksheet.selectRange() method which requires parameters specifying the start row, start column, total number of rows and total number of columns.
//Select Excel Cell Range i.e. C4:F7. int startRow = 3; int startColumn = 2; int totalRows = 4; int totalColumns = 4; //Select Excel cell range with the specified parameters. workbook.getWorksheets().get(0).selectRange(startRow, startColumn, totalRows, totalColumns, true);
After the execution of this code, the range will be selected as shown in this image.