View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Martin Fishlock Martin Fishlock is offline
external usenet poster
 
Posts: 694
Default Pasting search results not advancing row between matches

this should work

If Range("B3") < "" Then
With Worksheets("Movies").Range("B:B")
Set c = .Find(cellval, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
Sheets("Movies").Range(c.Address).Copy
' changed this to check column 1(A))
Set rng = Sheets("Main").Cells( _
Rows.Count,1).End(xlUp)(2)
rng.PasteSpecial xlValues
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

but it may be faster to do this:


If Range("B3") < "" Then
Set rng = Sheets("Main").Cells( _
Rows.Count,2).End(xlUp)(2).offset(0,-1)
offsetptr=0
With Worksheets("Movies").Range("B:B")
Set c = .Find(cellval, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
Sheets("Movies").Range(c.Address).Copy
' changed
rng.offset(offsetpr,0).PasteSpecial xlValues
offsetptr=offsetptr+1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With
--

Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Jon" wrote:

I am trying to paste search results into my 'Main' tab in an Excel
Book. I perform the search ok but every time I try to paste results,
they end up all pasting in the same cell, thus overwriting one another.
Here is part of mu code:

If Range("B3") < "" Then

With Worksheets("Movies").Range("B:B")
Set c = .Find(cellval, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do

Sheets("Movies").Range(c.Address).Copy
Set rng = Sheets("Main").Cells(Rows.Count,
2).End(xlUp)(2).Offset(0, -1)

rng.PasteSpecial xlValues

Set c = .FindNext(c)

Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With


Anyone know whats going wrong here? Any help is appreciated, thanks!