View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Kilmer[_2_] Bob Kilmer[_2_] is offline
external usenet poster
 
Posts: 71
Default 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