Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Find Column to use based on Name of Header

You would first have to define the range of headers. Then search that range
for the header text using Find. That will give you a column number that you
can assign to a variable, say ColNum. Then your code has to be re-written
to something like:
Set Rng = Range(Cells(2,ColNum), Cells(2,ColNum).End(xlDown)).
Please post back if this doesn't work for you or if you need more. HTH
Otto
"DJS" wrote in message
...
Hello~

~~~~~~~~~~~~~~
Here is a snippet of my code:

Set rng = Range(Range("J2"), Range("J2").End(xlDown))
~~~~~~~~~~~~~~

Instead of referencing Column J (as above), I would like to find the
correct
Column based on the name of the column header (in this case it is "VIN").

Thanks.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Find Column to use based on Name of Header

Don
This macro sets the range of the column header row (assuming it's row 1)
and asks for the column header to search for, then finds the column number
of the column that has that column header.
Watch out for line wrapping in this message. The line that starts with "Set
RngHeaders" ends with "xl(ToLeft)).
The line that starts with "ColNum=" ends with "Column".
Perhaps it would be more helpful to you if you send me your file (or a file
that looks like your file) so I can see the whole task you are trying to
accomplish. I need just the layout of your data, not the actual data. My
email address is . Remove the "nop" from this address.
HTH Otto
Sub GetColNum()
Dim ColNum As Long
Dim RngHeaders As Range
Dim ColHeader As String
'Set the rng of the column headers
Set RngHeaders = Range("A1", Cells(1, Columns.Count).End(xlToLeft))
'Get the column header to search for
ColHeader = InputBox("Enter the column header to find.")
'Find the column number
ColNum = RngHeaders.Find(What:=ColHeader, LookAt:=xlWhole).Column
End Sub

"DJS" wrote in message
...
Thanks for the assistance Otto, but I can't seem to figure out what method
or
property to use to fetch the column number.
I understand I need to search the first row for my header name, but how do
I
extract the column number?
Could you possibly point me in the correct direction?

TIA
--Don

"Otto Moehrbach" wrote:
You would first have to define the range of headers. Then search that
range
for the header text using Find. That will give you a column number that
you
can assign to a variable, say ColNum. Then your code has to be
re-written
to something like:
Set Rng = Range(Cells(2,ColNum), Cells(2,ColNum).End(xlDown)).
Please post back if this doesn't work for you or if you need more. HTH
Otto
"DJS" wrote in message
...
Hello~

~~~~~~~~~~~~~~
Here is a snippet of my code:

Set rng = Range(Range("J2"), Range("J2").End(xlDown))
~~~~~~~~~~~~~~

Instead of referencing Column J (as above), I would like to find the
correct
Column based on the name of the column header (in this case it is
"VIN").

Thanks.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Return column header based on last value in row C. Excel Worksheet Functions 3 April 12th 10 08:53 AM
Returning Column Header based on Row and Value Chad DiGregorio New Users to Excel 3 July 6th 09 07:09 PM
pick from table based on row and column header PBcorn Excel Worksheet Functions 2 June 29th 08 07:00 PM
Find First Non blank cell than find column header and return that value Silver Rose Excel Worksheet Functions 10 April 30th 07 05:56 PM
macro to hide column based on header Todd[_6_] Excel Programming 6 September 4th 03 04:34 AM


All times are GMT +1. The time now is 08:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"