How do I find text, returning the cell address

M

Mikeal

I am trying to find text, but once found I need to know the cell address so I
can continue using it in a if statement?
 
M

Myrna Larson

If you are using the Find method:

Set FoundCell = Cells.Find(......)
Addr = FoundCell.Address

Look at Help for the Address property for your options here.
 
H

Harlan Grove

Mikeal said:
I am trying to find text, but once found I need to know the cell address
so I can continue using it in a if statement?

In a formula or in VBA? If in a formula,

=CELL("Address",INDEX(SomeRange,MATCH(SomeText,SomeRange,0)))

would return the address of the first matching cell as long as SomeRange is
either single column or single row. If you have a 2D range to search, you
need a longer formula. If you were searching for 'foo' in A2:C4 containing

abd def foo
ghi jkl mno
pqr stu vwx
foo yzz zzz

and wanted C1 instead of A4, use the array formula

=CELL("Address",INDEX(A1:C4,MIN(IF(A1:C4="foo",ROW(A1:C4))),
MATCH("foo",INDEX(A1:C4,MIN(IF(A1:C4="foo",ROW(A1:C4))),0),0)))

If you wanted A4 instead of C1, use the array formula

=CELL("Address",INDEX(A1:C4,MATCH("foo",INDEX(A1:C4,0,
MIN(IF(A1:C4="foo",COLUMN(A1:C4)))),0),
MIN(IF(A1:C4="foo",COLUMN(A1:C4)))))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top