Why doesn't ths VBA Code work?

  • Thread starter Thread starter Mac Lingo
  • Start date Start date
M

Mac Lingo

Help!

I can run this code from inside a simple Macro called subroutine with ARG
replaced by a string. But when I put it in another function and call it
from within my own code, I get a 424 Error, "Object required" error. And it
was running until an hour ago. Anyidea what's going on?

Many thanks,
Mac Lingo
Berkeley, CA

=============================================================
The Code

Range("A1").Select

Set rng = Cells.Find(What:=ARG, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
 
I think the find isn't locating the ARG value on the activesheet. this means
then that No Object (a range) has been set and so it can't activate it.

try replacing you one liner with these extra lines:

Set rng = Cells.Find(What:=ARG, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)

If rng Is Nothing Then
MsgBox ARG & " not found on active sheet."
Else
rng.Activate
End If

HTH

Barry
 

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

Back
Top