View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Find a Cell Value

There is a definite benefit to doing it JLG's way. If the find does not find
anything then the code will crash. By assigning the found range to a range
object and then checking that the object is not nothing then you avoid the
error... There is still one remaining issue with the find and that is that by
not specifying all of the parameters the find will use whatever the current
values are. If your end user has changed some of the parameters then your
code will possibly not find what you ariginally intended... To be safe the
code should be more like this...

Sub copi()
Dim c As Range

Set c = Cells.Find(What:="My String", _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not c Is Nothing Then
c.Offset(0, 1).Copy Sheets("Destination").Range("newRange")
End If
End Sub

The above will not error out if the value is not found and the find will
work according to the parameters specified and not the current values of the
find parameters.
--
HTH...

Jim Thomlinson


"matt" wrote:

That worked perfect Gary. Thanks.
JLG if you read this is there a benefit of doing it your way? It seems more
complicated.

"Gary Keramidas" wrote:

one way
Cells.Find("My String").offset(,1).Copy

--


Gary


"matt" wrote in message
...
Hi,
I figuered out how to search through the sheet and find a string. With
something like Cells.Find("My String").Activate
How do I have it do a .Copy of the cell to the right of that one. So if it
finds the string in "B10" then I want it to Copy "C10".
Thanks in advance....