PC Review


Reply
Thread Tools Rate Thread

How do I find a column number for a cell containing a value

 
 
Gilgamesh
Guest
Posts: n/a
 
      4th Mar 2010
Hi,
I have a range of cells A1:CZ1 all of which have different values. I
need to find the column number for a cell that contains a certain value.
I know I can use cells.find which returns the value rather than the cell
reference, and I have seen other posts in this group to return a number when
the cell is known range(ColAddress).cells(1,1).column

I can easily put this in a simple loop but I was wondering if there was a
smarter way that could do it in one line using built-in functions. If it
was a loop it would have to be processed many times for the different values
I need to lookup slowing things down quite a bit.

Thanks

 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      4th Mar 2010
mycolumn=application.match(myvalue,range("a1:cz1"),0)

or use vba FIND with
if not mycol is nothing then msgbox mycol.column
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Gilgamesh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I have a range of cells A1:CZ1 all of which have different values. I
> need to find the column number for a cell that contains a certain value.
> I know I can use cells.find which returns the value rather than the cell
> reference, and I have seen other posts in this group to return a number
> when the cell is known range(ColAddress).cells(1,1).column
>
> I can easily put this in a simple loop but I was wondering if there was a
> smarter way that could do it in one line using built-in functions. If it
> was a loop it would have to be processed many times for the different
> values I need to lookup slowing things down quite a bit.
>
> Thanks


 
Reply With Quote
 
B Lynn B
Guest
Posts: n/a
 
      4th Mar 2010
cells.find can be used to return a row/column number or address or any number
of other properties the cell might have.

myRow = cells.find(What:="Joe Smith").row
myCol = cells.find(What:="Joe Smith").column
myAddr = cells.find(What:="Joe Smith").address


"Gilgamesh" wrote:

> Hi,
> I have a range of cells A1:CZ1 all of which have different values. I
> need to find the column number for a cell that contains a certain value.
> I know I can use cells.find which returns the value rather than the cell
> reference, and I have seen other posts in this group to return a number when
> the cell is known range(ColAddress).cells(1,1).column
>
> I can easily put this in a simple loop but I was wondering if there was a
> smarter way that could do it in one line using built-in functions. If it
> was a loop it would have to be processed many times for the different values
> I need to lookup slowing things down quite a bit.
>
> Thanks
>
> .
>

 
Reply With Quote
 
helene and gabor
Guest
Posts: n/a
 
      4th Mar 2010
Hello,
Enter formula in A2:
=if(a1=value($A$5),$A$5,"")
copy this formula from B2 to CZ1 by dragging.
Enter a number in A5, say 12.
You will see all your entries A1:CZ1 that contain a 12.

Regards,

Gabor Sebo




"Gilgamesh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I have a range of cells A1:CZ1 all of which have different values. I
> need to find the column number for a cell that contains a certain value.
> I know I can use cells.find which returns the value rather than the cell
> reference, and I have seen other posts in this group to return a number
> when the cell is known range(ColAddress).cells(1,1).column
>
> I can easily put this in a simple loop but I was wondering if there was a
> smarter way that could do it in one line using built-in functions. If it
> was a loop it would have to be processed many times for the different
> values I need to lookup slowing things down quite a bit.
>
> Thanks
>


 
Reply With Quote
 
Gilgamesh
Guest
Posts: n/a
 
      4th Mar 2010

"B Lynn B" <(E-Mail Removed)> wrote in message
news:C927CA84-B190-4E48-9F3A-(E-Mail Removed)...
> cells.find can be used to return a row/column number or address or any
> number
> of other properties the cell might have.
>
> myRow = cells.find(What:="Joe Smith").row
> myCol = cells.find(What:="Joe Smith").column
> myAddr = cells.find(What:="Joe Smith").address


Thank You

>
>
> "Gilgamesh" wrote:
>
>> Hi,
>> I have a range of cells A1:CZ1 all of which have different values. I
>> need to find the column number for a cell that contains a certain value.
>> I know I can use cells.find which returns the value rather than the cell
>> reference, and I have seen other posts in this group to return a number
>> when
>> the cell is known range(ColAddress).cells(1,1).column
>>
>> I can easily put this in a simple loop but I was wondering if there was a
>> smarter way that could do it in one line using built-in functions. If it
>> was a loop it would have to be processed many times for the different
>> values
>> I need to lookup slowing things down quite a bit.
>>
>> Thanks
>>
>> .
>>




 
Reply With Quote
 
helene and gabor
Guest
Posts: n/a
 
      8th Mar 2010
Hello,

I wrote a VBA program and inserted a:12 in columns 1,6,11,30,92 and 104.
The outputs are column numbers (1,6,...104) and the columns for these 12.s:
A,F,K,AD,CN and CZ.
The output is unsophisticated.

best regards,

Gabor Sebo
worksheet encl.



"Gilgamesh" <(E-Mail Removed)> wrote in message

"Gilgamesh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I have a range of cells A1:CZ1 all of which have different values. I
> need to find the column number for a cell that contains a certain value.
> I know I can use cells.find which returns the value rather than the cell
> reference, and I have seen other posts in this group to return a number
> when the cell is known range(ColAddress).cells(1,1).column
>
> I can easily put this in a simple loop but I was wondering if there was a
> smarter way that could do it in one line using built-in functions. If it
> was a loop it would have to be processed many times for the different
> values I need to lookup slowing things down quite a bit.
>
> Thanks
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
function - find first number in row > 0, return cell column number cate Microsoft Excel Programming 3 19th Apr 2011 09:44 PM
R: Re: function - find first number in row > 0, return cell column number r Microsoft Excel Programming 0 19th Apr 2011 09:44 PM
Find a number in a column then return a value from another cell Mark Dullingham Microsoft Excel Worksheet Functions 2 17th May 2010 09:57 AM
Find column number of last used cell in a row KG Old Wolf Microsoft Excel Programming 5 26th Sep 2009 10:48 PM
Find cell below last number in a column =?Utf-8?B?VHdvLUNhbnVja3M=?= Microsoft Excel Programming 5 20th May 2006 12:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:09 AM.