Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How to find a column

In VBA, how would I find a specific column ? I want the function
to return the column number of a column named "Sample"

Many Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How to find a column

Hi Jon

If it is a named range

MsgBox Range("Sample").Cells(1).Column


If you have a header with that name
Try this for the first row in Sheets("sheet1")

Sub test()
Dim FindString As String
Dim Rng As Range
FindString = "Sample"
Set Rng = Sheets("sheet1").Range("1:1").Find(What:=FindStrin g, _
After:=Range("A1"), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then MsgBox Rng.Column
End Sub



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Jon Turner" wrote in message ...
In VBA, how would I find a specific column ? I want the function
to return the column number of a column named "Sample"

Many Thanks




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to find a column

Ron addressed one possibility - here is another:
If you mean sample is text contained in the first row

Dim rng as Range
set rng = rows(1).Find("Sample")
if not rng is nothing then
rng.Entirecolumn.Select
else
msgbox "Sample not found"
End if

--
Regards,
Tom Ogilvy

"Jon Turner" wrote in message
...
In VBA, how would I find a specific column ? I want the function
to return the column number of a column named "Sample"

Many 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
FInd common data in one column then add number in adjacent column JT Excel Worksheet Functions 3 December 18th 09 10:20 PM
How to find duplicate cells in Column a & retrieve column B ghost Excel Discussion (Misc queries) 2 February 22nd 09 05:39 PM
find last row value in column when using MATCH to find column Bouce Excel Worksheet Functions 6 February 6th 08 10:16 PM
Find something in column a then find if column B matches criteria Darrell_Sarrasin via OfficeKB.com Excel Discussion (Misc queries) 8 November 28th 07 09:40 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


All times are GMT +1. The time now is 04:15 AM.

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"