Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Column location

Hi

How do I search the columns for a specific column name so I can
reference that column number in future code?

for ex:

happy sad mad laugh

I need to know that mad is column 4.



Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Column location

Sub FindColumn()
Dim cell As Range, FoundColumn As String
For Each cell In ActiveSheet.Range("A1",
ActiveSheet.Range("IV1").End(xlToLeft))
If lower(cell) = "mad" Then
FoundColumn = cell.Column
MsgBox FoundColumn
End If
Next cell

End Sub

I've made the test case insensitive using lower, if you want it case
sensitive then remove the lower method.

HTH
Cal


" wrote:

Hi

How do I search the columns for a specific column name so I can
reference that column number in future code?

for ex:

happy sad mad laugh

I need to know that mad is column 4.



Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Column location

mc=rows(2).find("mad").column
msgbox mc

--
Don Guillett
SalesAid Software

wrote in message
oups.com...
Hi

How do I search the columns for a specific column name so I can
reference that column number in future code?

for ex:

happy sad mad laugh

I need to know that mad is column 4.



Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Column location

one more

Dim res as Variant
res = Application.Match("mad",Range("A1:IV1"),0)
if not iserror(res) then
msgbox "Column is " & res
else
msgbox "Column heading not found"
End sub

--
Regards,
Tom Ogilvy


" wrote:

Hi

How do I search the columns for a specific column name so I can
reference that column number in future code?

for ex:

happy sad mad laugh

I need to know that mad is column 4.



Thanks


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Column location

Thank you all for you help. They all worked.

Smythe32



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Column location

But the last two were much faster than looking at each cell.

--
Don Guillett
SalesAid Software

wrote in message
ups.com...
Thank you all for you help. They all worked.

Smythe32



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Column location

picoseconds vs milliseconds? Lets be honest, unless you are dealing with
thousands entries, the user is not going to notice a difference in 255
columns headings.

Although I do believe your solution was the best just based on simplicity.



"Don Guillett" wrote:

But the last two were much faster than looking at each cell.

--
Don Guillett
SalesAid Software

wrote in message
ups.com...
Thank you all for you help. They all worked.

Smythe32




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Column location

Although I do believe your solution was the best just based on simplicity.

then you need to look harder. <g A lot of times half a solution looks
simpler.

It has no error checking and doesn't overtly declare other persistent
arguments which could result in a crap shoot as to whether it actually works
or not. It could raise intermittent 91 errors when the match is not made
with no clear indication of why.

Not to say that find isn't the best solution - just to say that this
implementation of it is problematic because of omissions.

No criticism of Don who was just plopping down a worthy concept with minimal
investment in time - but you appear to have made you assessment on face
value.

Just a friendly observation and certainly my opinion. <g

--
Regards,
Tom Ogily

"CBrine" (donotspam) wrote in message
...
picoseconds vs milliseconds? Lets be honest, unless you are dealing with
thousands entries, the user is not going to notice a difference in 255
columns headings.

Although I do believe your solution was the best just based on simplicity.



"Don Guillett" wrote:



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
Reading from set Row/Column location Ant Excel Discussion (Misc queries) 4 May 14th 09 09:54 AM
Finding the location of MAX value in column milly Excel Discussion (Misc queries) 2 May 11th 07 12:15 PM
find location max value in column rroach Excel Discussion (Misc queries) 3 July 13th 05 10:27 PM
find cell location of max value in column rroach Excel Programming 6 June 6th 05 04:59 PM
How can I put a cell location (ie. row and column #, not value in. KyWilde Excel Programming 4 April 20th 05 01:34 AM


All times are GMT +1. The time now is 03:05 PM.

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

About Us

"It's about Microsoft Excel"