PDA

View Full Version : Selecting A Cell - In A Column By its heading



Rabi
11-23-2007, 05:47 AM
Hi everybody

I am a beginner in Excel.

My problem is that the sequence of Colunms in my worksheet, with the similar data, keep changing. For example, an "Employee Name" may appear in column 3 or 5 etc.

For this reason, I want to select a cell within any column by its heading rather than "A", "B", "C" etc.
For example, I want to select a cell as below:

Cells(5, "SN").Select - which of course is not accepted by Excel:(

Similarly, I want to use Range with a column by its heading.

Or

I will like to know the Column number for the column with the heading "SN", for example.

I will appreciate any help.

Regards,

rory
11-23-2007, 06:07 AM
You can use something like:
Dim varCol As Variant
varCol = Application.Match("SN", ActiveSheet.Rows(1), 0)
If IsError(varCol) Then Exit Sub

This assumes the headers are in row 1.

Rabi
11-24-2007, 07:54 AM
Thanks very much for the valuable hint.

Regards,