Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel Macro question? Column position

Say I have a column name "TEST". I would like to find the position of this
column and then assign this number to a variable.

If "TEST" is the fifth column in the spreadsheet...then the resulting value
I'm looking for is var = 5

Anyone?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Excel Macro question? Column position

one way:

Dim var As Long
var = Range("TEST").Column


In article ,
"Arul" wrote:

Say I have a column name "TEST". I would like to find the position of this
column and then assign this number to a variable.

If "TEST" is the fifth column in the spreadsheet...then the resulting value
I'm looking for is var = 5

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel Macro question? Column position

Thanks for the response...

I'm getting the following error...
Method 'Range' of object '_Global' failed

Any idea why?

"JE McGimpsey" wrote:

one way:

Dim var As Long
var = Range("TEST").Column


In article ,
"Arul" wrote:

Say I have a column name "TEST". I would like to find the position of this
column and then assign this number to a variable.

If "TEST" is the fifth column in the spreadsheet...then the resulting value
I'm looking for is var = 5


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel Macro question? Column position

do you have an Insert=Name=Define
Name:= Test
Refersto:=Sheet1!$E:$E

or something like that. If not, that is why you get the error.

If by named test, you mean E1 has the word Test in it.

Sub AAA()
Dim res As Variant, vVar As Variant

res = Application.Match("Test", Rows(1), 0)
If Not IsError(res) Then
vVar = res
Debug.Print vVar
Else
MsgBox "Not found"
End If

End Sub


--
Regards,
Tom Ogilvy

"Arul" wrote in message
...
Thanks for the response...

I'm getting the following error...
Method 'Range' of object '_Global' failed

Any idea why?

"JE McGimpsey" wrote:

one way:

Dim var As Long
var = Range("TEST").Column


In article ,
"Arul" wrote:

Say I have a column name "TEST". I would like to find the position of

this
column and then assign this number to a variable.

If "TEST" is the fifth column in the spreadsheet...then the resulting

value
I'm looking for is var = 5




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
Row position of specified column and value engineer Excel Worksheet Functions 12 December 23rd 09 11:24 PM
function for Column Position nastech Excel Discussion (Misc queries) 4 October 22nd 05 12:56 AM
Excel formula to find position of the contents of a cell within a column. [email protected] Excel Discussion (Misc queries) 3 September 26th 05 03:52 PM
Finding Column Position Brian Mann Excel Discussion (Misc queries) 1 September 22nd 05 09:26 AM
#VALUE! position in column of data Todd Huttenstine Excel Programming 1 April 7th 04 11:28 PM


All times are GMT +1. The time now is 12:32 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"