View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Gregory Turk Gregory Turk is offline
external usenet poster
 
Posts: 6
Default Find from one sheet to another

I am trying to write some code for Excel that takes the selected value of a
cell on one sheet and searches for it on a second sheet ("Data") in the same
workbook, but within a specific range around the active cell on the second
sheet. My code selects the range on the second sheet without a problem but
errors when attempting to use the find method. Here's the code:

Sub ToData()

Dim SearchTarget As String
Dim RngTop, RngBot As Integer

SearchTarget = Selection 'active cell on sheet 1

Worksheets("Data").Activate
RngRow = ActiveCell.Row

'demarcates range
RngBot = Cells(RngRow, 3).End(xlDown).Row
RngTop = Cells(RngRow, 3).End(xlUp).Row
Set Rng = Range("A" & RngTop, "A" & RngBot)
Rng.Select
'if the last line containing the Find function is omitted, the range is
selected as intended
'when the following Find is added, an error occurs

Rng.Find(What:=SearchTarget, LookAt:= _
xlPart, SearchDirection:=xlNext, MatchCase:=False).Activate

End Sub

Thanks for the help!

Greg