Cells.Find

A

Arturo

Looping through a column in sheet1 storing the first cell in variable
Y_CellBase, followed by activating sheet 2 and searching for that value. .If
there’s a match I’ve got down what to do. If there’s no match on sheet 2 I
need to do something else. I’m not sure how to handle the issue of no match
being found. So spastically put if match found then do this else do that….

Worksheets(1). Activate
((Looping code here starting at first cell))
Y_CellBase = ActiveCell.Value
Worksheets(2).Activate

Cells.Find(What:=Y_CellBase, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Activate


Appreciatively,
Arturo
 
J

Jim Thomlinson

Try something like this...

Dim rngFound as range
Worksheets(2).Activate

set rngFound = Cells.Find(What:=Y_CellBase, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

if rngFound is Nothing then
msgbox "sorry... not found"
else
rng.select
end if
 
A

Arturo

Worksheets(2).Activate
Set rngFound = Cells.Find(What:=Y_CellBase, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If rngFound Is Nothing Then
MsgBox "sorry... not found"
Else
 
J

Jim Thomlinson

When I said "like this" I guess I meant for you to fix the silly mistakes...
;-)

Nice catch on that goof...
 

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