What in the edited code below makes it crash?????

S

Simon

Current code:

MyWBSEL.Activate
Sheets("Elite").Select
Range("G4").Select
Selection.End(xlDown).Select
Application.CutCopyMode = False
Selection.Copy
MyWBAccRep.Activate
Cells.Find("latest").Select
ActiveCell.Offset(21, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False

Edited:

MyWBSEL.Sheets("Elite").Range("G4")..End(xlDown).Copy Destination:=
MyWBAccRep.Cells.Find("latest").Cell.Offset(21, 0)



The edited code crashes. Why? The workbooks are Dim'd and Set and
opened.
 
J

Jim Thomlinson

if you do not find the word latest then it will crash...

Cells.Find("latest").Select

When you do a find you really need to specify the optional paramters,
otherwise whatever the user left them at last will be used...

dim rngFound as range

set rngfound = cells.find(what:="latest", LookAt:=xlpart,
lookin:=xlformulas, matchcase:=false)

if rngfound is nothing then
msgbox "latest was not found"
else
rngfound.select
endif
 

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