Sanil Sahadevan
Sanil Sahadevan

Reputation: 23

How To Select Entire Column Except Header/First Row In Excel using VBA

I am trying to make a selection of an entire column except the first row. I used the following code which i got from https://www.extendoffice.com/documents/excel/1628-excel-select-column-except-header-first-row.html

Sub SelectColumn()
Dim xColIndex As Integer
Dim xRowIndex As Integer
xColIndex = Application.ActiveCell.Column
xRowIndex = Application.ActiveSheet.Cells(Rows.Count, xColIndex).End(xlUp).Row
Range(Cells(2, xColIndex), Cells(xRowIndex, xColIndex)).Select
End Sub

but the RowIndex variable reads to the value 1. So the section happens from Row2 to Row1 instead of Row2 to the Last row. How can i get this corrected

Upvotes: 1

Views: 10568

Answers (1)

SJR
SJR

Reputation: 23081

If you really need to select the whole column (why?) then this. In your example you can't have any data in the relevant column.

Range(Cells(2, xColIndex), Cells(rows.count, xColIndex)).Select

Upvotes: 1

Related Questions