Thread: Range Problem
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Rowan Drummond
 
Posts: n/a
Default Range Problem

You would be better off cutting and pasting your code directly from the
VBE into your message. There are a number of typos in here which makes
it hard to say what the real problem is eg
Cells.Find(What = l1).Activate
should be
Cells.Find(What:= l1).Activate

Two pointers when using the find method. One it will remember the
settings from the last time it was used either manually or in a macro so
you should specify all relavant parameters.
Secondly you should cater for the fact that you may not find what you
are looking for. So your code would look something like:

Dim fndCell as range
Set fndCell = Cells.Find(What:=l2, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext _
, MatchCase:=False)
If not fndCell is nothing then
fndcell.activate
else
msgbox "Not Found"
End if

Hope this helps
Rowan

jesmin wrote:
Thanks. No syntex wise code is fine(I was typing actually).
Only the 2nd FIND case its not working. 1st cells.FIND working well.
2nd cells.find(what:=var).activate --this part is not working

Am I doing wrong in writing both cells.FIND similar way(Ommiting other
find parameters).???
l1 = Application.WorksheetFunction.Max(rng2)
Cells.Find(What = l1).Activate------working fine

l2 = Application.WorksheetFunction.Max(rngt)
Cells.Find(What = l2).Activate------Error: Object or With block not set