Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you all for you help. They all worked.
Smythe32 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Reading from set Row/Column location | Excel Discussion (Misc queries) | |||
Finding the location of MAX value in column | Excel Discussion (Misc queries) | |||
find location max value in column | Excel Discussion (Misc queries) | |||
find cell location of max value in column | Excel Programming | |||
How can I put a cell location (ie. row and column #, not value in. | Excel Programming |