ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Capturing Row of Selection.Find? (https://www.excelbanter.com/excel-programming/351088-capturing-row-selection-find.html)

[email protected]

Capturing Row of Selection.Find?
 
Gang -

How do I capture the row of a successful Selection.Find?

I did find out that Selection.Find returns -1. What's that mean?

And how would I do this without making a selection? The macro recorder
doesn't help there. I ended up using a "For each cell" loop looking for
an equality and incrementing/capturing a counter.


Thanks in advance.

....best, Michael

Toppers

Capturing Row of Selection.Find?
 
rowno = Selection.Find("123").Row

I posted this to a previous posting from you!

" wrote:

Gang -

How do I capture the row of a successful Selection.Find?

I did find out that Selection.Find returns -1. What's that mean?

And how would I do this without making a selection? The macro recorder
doesn't help there. I ended up using a "For each cell" loop looking for
an equality and incrementing/capturing a counter.


Thanks in advance.

....best, Michael


Toppers

Capturing Row of Selection.Find?
 
...... by mistake! My fault!

" wrote:

Gang -

How do I capture the row of a successful Selection.Find?

I did find out that Selection.Find returns -1. What's that mean?

And how would I do this without making a selection? The macro recorder
doesn't help there. I ended up using a "For each cell" loop looking for
an equality and incrementing/capturing a counter.


Thanks in advance.

....best, Michael


Tom Ogilvy

Capturing Row of Selection.Find?
 
Using Toppers approach is fine if you are guaranteed that the target value
will be found. If not, it is better to set a reference to the result of the
find command and then test if Find was successful

Dim rng as Range
set rng = Columns("C").Find("123")
if not rng is nothing then
rw = rng.row
Else
msgbox "123 not found"
exit sub
End if

--
Regards,
Tom Ogilvy


wrote in message news:w8rAf.9318$bF.2432@dukeread07...
Gang -

How do I capture the row of a successful Selection.Find?

I did find out that Selection.Find returns -1. What's that mean?

And how would I do this without making a selection? The macro recorder
doesn't help there. I ended up using a "For each cell" loop looking for
an equality and incrementing/capturing a counter.


Thanks in advance.

...best, Michael




[email protected]

Capturing Row of Selection.Find?
 
Tom -

Thank you. Toppers message never made it to my news server, but I see
the way to go.

Thanks again.
....Hash

In article ,
"Tom Ogilvy" wrote:

Using Toppers approach is fine if you are guaranteed that the target value
will be found. If not, it is better to set a reference to the result of the
find command and then test if Find was successful

Dim rng as Range
set rng = Columns("C").Find("123")
if not rng is nothing then
rw = rng.row
Else
msgbox "123 not found"
exit sub
End if



All times are GMT +1. The time now is 05:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com