Select multiple rows and columns – VBA Excel

select rows and columns vba excel

Objective

To select multiple rows and columns in VBA Excel.

Approach

In the code below we have showcased how to select multiple rows or columns, these rows and columns can be continuous (or adjacent) or not. In the image below we can see how we can select them.

Select multiple rows which are adjacent to each other

In the code below we are selecting 3rd and 4th at the same time.

Sub SelectMultipleRows()

'Select continious rows
Rows("3:4").Select

End Sub

 

In the image below we can see that both the rows are selected at the same time.

 

select rows vba excel

 

Select multiple rows which are not adjacent to each other

In the code below we are trying to select row 1,2,4,6 at the same time.We can also see here that not all of these rows are adjacent, which means there is a row in between which is not selected.

Sub SelectMultipleRowsNonAdjacent()

'Select multiple rows which are not adjacent
Range("1:2,4:4,6:6").Select

End Sub

 

select non adjacent rows vba excel

 

Select columns which are adjacent to each other

Here we are selecting column B and C together.

Sub SelectMultipleColumns()
Columns("B:C").Select
End Sub

 

In the image below code we can see have selected column B and C together.

 

select columns vba excel

 

Select columns which are not adjacent to each other

In the column A,B,D,E together. Here column C is not selected.

 

Sub SelectNonAdjacentColumns()

'Select columns which are not adjacent or continuous
Range("A:B,D:D,E:E ").Select

End Sub

 

select non adjacent columns vba excel