Macro works, then doesn't

O

Oddball

Why does this code work one day, then the next it does not?
I have to write a new code every time I launch this WB WHY??

My security is set to LOW now, and trusted sources are both checked.
It ONLY happenes in this workbook, the codes work in others just fine, what
could be the problem with this workbook ( if the code is right?)
Thanks in advance if you can help.

Sub FindThis()
Dim rngToSearch As Range
Dim rngFound As Range
Dim wks As Worksheet
Set wks = ActiveSheet
Set rngToSearch = Worksheets("Schedule").Range("A4:A5205")
Set rngFound = rngToSearch.Find(What:=wks.Range("$A$1"), _
LookAt:=xlPart, MatchCase:=False)

If Not rngFound Is Nothing Then
Application.Goto Range(rngFound.Address), True


Else
MsgBox "Not Found"
End If
End Sub
 
D

Dave Peterson

I'd specify all the parms in the .find statement.

And this line:
Application.Goto Range(rngFound.Address), true
will go to the same address as rngFound--but on the activesheet.

Maybe you want:
Application.Goto rngFound, true

=====
And make sure you save that workbook after you type in the code. (Are you
putting the code in that same workbook--and that workbook isn't being deleted
and recreated each day???)
 
O

Oddball

Dave,
Thanks for your reply.
This has also had no effect.
I wonder... I have been creating all my workbooks on a different computer ,
then I copied them, took them home and mixed and matched my already proven
macros from my prior WB's into this one that I just created here at home.
I obviously had to edit the addresses of the ranges within most of the
codes, but the very first time I edited them, they worked... all day, until I
saved and shut down my PC .I started it up again the next day, opened this
WB to continue working on scheduling my employees but ALL the various "Find"
macros ( all are copied from other WB's, renamed and edited) do not work.
All the ones I've actually written (recorded) while working on this WB work
just fine.
All the "Find" macros work in their original WBs on this PC.

Btw, the PC the other WB's were created on no longer exists, I have migrated
all WBs home.
 
D

Dave Peterson

What does "not work" mean?

Does it mean that the macro doesn't even run (make sure macros are enabled).

Does it mean that you get the "Not Found" message back? Maybe you didn't type a
string that was found???
 

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