Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Find all then paste not working.

Here is the situation. I have this code and it is working fine except one
thing. I would like to paste all of the cells that are found, as it stands
now it is only finding and pasting the first instance of a word. ie. if you
search for a word that is in the ss twice it is only finding the first one.
Thanks
Code:
Private Sub cmdFind_Click()
Dim wksCopyFrom As Worksheet
Dim wksCopyTo As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngCopyTo As Range

Set wksCopyTo = Sheets("Search_Add")
For Each wksCopyFrom In Worksheets
If wksCopyFrom.Name < wksCopyTo.Name And _
wksCopyFrom.Name < "Search_Add" Then 'sheets you don't want searched
Set rngToSearch = wksCopyFrom.Cells
Set rngFound = rngToSearch.Find(txtFind.Text, , xlValues,
LookAt:=xlPart)
If Not rngFound Is Nothing Then
'If rngCopyTo.Offset.Value < "" Then
'rngFound.Offset(1, 0).EntireRow.Insert
Set rngCopyTo = wksCopyTo.Cells(Rows.Count,
"A").End(xlUp).Offset(1, 0)
rngFound.EntireRow.Copy rngCopyTo
End If
End If
'End If
Next wksCopyFrom
txtFind.Text = ""
Sheets("Search_Add").Activate
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Find all then paste not working.

Private Sub cmdFind_Click()
Dim wksCopyFrom As Worksheet
Dim wksCopyTo As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngCopyTo As Range
Dim sAddr as String

Set wksCopyTo = Sheets("Search_Add")
For Each wksCopyFrom In Worksheets
If wksCopyFrom.Name < wksCopyTo.Name And _
wksCopyFrom.Name < "Search_Add" Then 'sheets you don't want
searched
Set rngToSearch = wksCopyFrom.Cells
Set rngFound = rngToSearch.Find(txtFind.Text, _
, xlValues, LookAt:=xlPart)
If Not rngFound Is Nothing Then
sAddr = rngFound.Address
do
Set rngCopyTo = wksCopyTo.Cells(Rows.Count, _
"A").End(xlUp).Offset(1, 0)
rngFound.EntireRow.Copy rngCopyTo
set rngFound = rngToSearch.FindNext(rngFound)
loop while sAddr < rngFound.Address
End If
End If
Next wksCopyFrom
txtFind.Text = ""
Sheets("Search_Add").Activate
End Sub

--
Regards,
Tom Ogilvy


"Mark Cover" wrote in message
...
Here is the situation. I have this code and it is working fine except one
thing. I would like to paste all of the cells that are found, as it

stands
now it is only finding and pasting the first instance of a word. ie. if

you
search for a word that is in the ss twice it is only finding the first

one.
Thanks
Code:
Private Sub cmdFind_Click()
Dim wksCopyFrom As Worksheet
Dim wksCopyTo As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngCopyTo As Range

Set wksCopyTo = Sheets("Search_Add")
For Each wksCopyFrom In Worksheets
If wksCopyFrom.Name < wksCopyTo.Name And _
wksCopyFrom.Name < "Search_Add" Then 'sheets you don't want

searched
Set rngToSearch = wksCopyFrom.Cells
Set rngFound = rngToSearch.Find(txtFind.Text, , xlValues,
LookAt:=xlPart)
If Not rngFound Is Nothing Then
'If rngCopyTo.Offset.Value < "" Then
'rngFound.Offset(1, 0).EntireRow.Insert
Set rngCopyTo = wksCopyTo.Cells(Rows.Count,
"A").End(xlUp).Offset(1, 0)
rngFound.EntireRow.Copy rngCopyTo
End If
End If
'End If
Next wksCopyFrom
txtFind.Text = ""
Sheets("Search_Add").Activate
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Find all then paste not working.

Tom,
Works like a charm..
you are the man thinks so much for your help.

"Tom Ogilvy" wrote:

Private Sub cmdFind_Click()
Dim wksCopyFrom As Worksheet
Dim wksCopyTo As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngCopyTo As Range
Dim sAddr as String

Set wksCopyTo = Sheets("Search_Add")
For Each wksCopyFrom In Worksheets
If wksCopyFrom.Name < wksCopyTo.Name And _
wksCopyFrom.Name < "Search_Add" Then 'sheets you don't want
searched
Set rngToSearch = wksCopyFrom.Cells
Set rngFound = rngToSearch.Find(txtFind.Text, _
, xlValues, LookAt:=xlPart)
If Not rngFound Is Nothing Then
sAddr = rngFound.Address
do
Set rngCopyTo = wksCopyTo.Cells(Rows.Count, _
"A").End(xlUp).Offset(1, 0)
rngFound.EntireRow.Copy rngCopyTo
set rngFound = rngToSearch.FindNext(rngFound)
loop while sAddr < rngFound.Address
End If
End If
Next wksCopyFrom
txtFind.Text = ""
Sheets("Search_Add").Activate
End Sub

--
Regards,
Tom Ogilvy


"Mark Cover" wrote in message
...
Here is the situation. I have this code and it is working fine except one
thing. I would like to paste all of the cells that are found, as it

stands
now it is only finding and pasting the first instance of a word. ie. if

you
search for a word that is in the ss twice it is only finding the first

one.
Thanks
Code:
Private Sub cmdFind_Click()
Dim wksCopyFrom As Worksheet
Dim wksCopyTo As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngCopyTo As Range

Set wksCopyTo = Sheets("Search_Add")
For Each wksCopyFrom In Worksheets
If wksCopyFrom.Name < wksCopyTo.Name And _
wksCopyFrom.Name < "Search_Add" Then 'sheets you don't want

searched
Set rngToSearch = wksCopyFrom.Cells
Set rngFound = rngToSearch.Find(txtFind.Text, , xlValues,
LookAt:=xlPart)
If Not rngFound Is Nothing Then
'If rngCopyTo.Offset.Value < "" Then
'rngFound.Offset(1, 0).EntireRow.Insert
Set rngCopyTo = wksCopyTo.Cells(Rows.Count,
"A").End(xlUp).Offset(1, 0)
rngFound.EntireRow.Copy rngCopyTo
End If
End If
'End If
Next wksCopyFrom
txtFind.Text = ""
Sheets("Search_Add").Activate
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Paste and Paste Special No Longer Working - Excel 2003 SheriJ Excel Discussion (Misc queries) 2 January 15th 09 09:23 PM
Cut and Paste Stopped Working Minitman Excel Discussion (Misc queries) 2 November 9th 08 05:47 AM
Paste Special Not Working Joe VW Excel Worksheet Functions 1 November 1st 06 06:24 PM
I need to find a macro to find data cut and paste to another colu. Rex Excel Programming 6 December 7th 04 09:22 AM
Worksheet_Change not working when using paste papou[_7_] Excel Programming 1 September 5th 03 12:57 PM


All times are GMT +1. The time now is 09:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"