ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Referrring to cells by their column header (https://www.excelbanter.com/excel-programming/298000-re-referrring-cells-their-column-header.html)

Bob Kilmer[_2_]

Referrring to cells by their column header
 
You can use Find. For instance, the following sets the value of the sixth
cell in the column on the active worksheet whose header (in the first row)
is "abc" to "P".

Rows(1).Find("abc").EntireColumn.Rows(6).Value = "P"

Or set a reference to the column to use later, but check to see if found

Dim rng as Range
On Error Resume Next
Set rng = Rows(1).Find("abc").EntireColumn
If rng is Nothing then 'range not found
'do something
Else
'do something else
rng.Rows(6).Value = "P"
End If
On Error Goto 0

Bob

"Fred Smith" wrote in message
...
I'm working with an export file that contains several columns each headed

by
a description. However, there's no guarantee what order the columns will

be
in.

In VBA, is there a way I can refer to a cell, and/or a column, by its
description (much like the sort function does)?

--
Thanks,
Fred
Please reply to newsgroup, not e-mail







All times are GMT +1. The time now is 01:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com