Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Find and Copy

I am trying to search for and copy all instances of a found string in
the workbook to another workbook. I found code (not mine, I can't get a
batch file to echo hello) to search and find the string, but don't know
how to get it to write every instance it finds to another new workbook.
Can someone help?

Thanks

Sub FindAcrossMultipleSheets()
Dim findStr As String
Dim wkSht As Worksheet
Dim found As Range
Dim foundAddr As String
Dim yesNoResult As Integer


findStr = InputBox("Find what:", "Find Across Sheets",
ActiveCell.Value)
On Error Resume Next
For Each wkSht In Sheets
With wkSht

'Set found = .Cells.Find(What:=findStr, After:=.Range("A1"), _
MatchCase:=True)

Set found = .Cells.Find(What:=findStr, LookIn:=xlValues, _
Lookat:=xlPart, MatchCase:=False)

'Set cll = .Find(FindString, LookIn:=xlValues, _
LookAt:=xlPart, MatchCase:=False)


If Not found Is Nothing Then
foundAddr = found.Address
Do
.Activate
found.Activate
yesNoResult = MsgBox("Find " & findStr & " Again?",
vbYesNo)
If yesNoResult = vbNo Then Exit For
Set found = .Cells.FindNext(After:=ActiveCell)
Loop Until found.Address = foundAddr
Set found = Nothing
End If
End With
Next wkSht
If found Is Nothing Then MsgBox findStr & " not found."
On Error GoTo 0
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Find and Copy

Sub FindAcrossMultipleSheets()
Dim findStr As String
Dim wkSht As Worksheet
Dim found As Range
Dim foundAddr As String
Dim yesNoResult As Integer
Dim destSht as worksheet
Dim i as Long

Set destSht = Workbooks("Output.xls").Worksheets(1)
i = 1
findStr = InputBox("Find what:", "Find Across Sheets",
ActiveCell.Value)
On Error Resume Next
For Each wkSht In Sheets
With wkSht

'Set found = .Cells.Find(What:=findStr, After:=.Range("A1"), _
MatchCase:=True)

Set found = .Cells.Find(What:=findStr, LookIn:=xlValues, _
Lookat:=xlPart, MatchCase:=False)

'Set cll = .Find(FindString, LookIn:=xlValues, _
LookAt:=xlPart, MatchCase:=False)


If Not found Is Nothing Then
foundAddr = found.Address
Do
.Activate
found.Activate
found.copy Destination:=destsht.cells(i,1)
i = i + 1
yesNoResult = MsgBox("Find " & _
findStr & " Again?",vbYesNo)
If yesNoResult = vbNo Then Exit For
Set found = .Cells.FindNext(After:=ActiveCell)
Loop Until found.Address = foundAddr
Set found = Nothing
End If
End With
Next wkSht
If found Is Nothing Then MsgBox findStr & " not found."
On Error GoTo 0
End Sub

I had it copy just the cell, but if you want the whole row, change it to

found.EntireRow.copy DestSht.Cells(i,1)

--
Regards,
Tom Ogilvy


"Fred" wrote in message
oups.com...
I am trying to search for and copy all instances of a found string in
the workbook to another workbook. I found code (not mine, I can't get a
batch file to echo hello) to search and find the string, but don't know
how to get it to write every instance it finds to another new workbook.
Can someone help?

Thanks

Sub FindAcrossMultipleSheets()
Dim findStr As String
Dim wkSht As Worksheet
Dim found As Range
Dim foundAddr As String
Dim yesNoResult As Integer


findStr = InputBox("Find what:", "Find Across Sheets",
ActiveCell.Value)
On Error Resume Next
For Each wkSht In Sheets
With wkSht

'Set found = .Cells.Find(What:=findStr, After:=.Range("A1"), _
MatchCase:=True)

Set found = .Cells.Find(What:=findStr, LookIn:=xlValues, _
Lookat:=xlPart, MatchCase:=False)

'Set cll = .Find(FindString, LookIn:=xlValues, _
LookAt:=xlPart, MatchCase:=False)


If Not found Is Nothing Then
foundAddr = found.Address
Do
.Activate
found.Activate
yesNoResult = MsgBox("Find " & findStr & " Again?",
vbYesNo)
If yesNoResult = vbNo Then Exit For
Set found = .Cells.FindNext(After:=ActiveCell)
Loop Until found.Address = foundAddr
Set found = Nothing
End If
End With
Next wkSht
If found Is Nothing Then MsgBox findStr & " not found."
On Error GoTo 0
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Find and Copy

Most helpful.

Thank you very much.

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
find and copy it.. reza Excel Discussion (Misc queries) 1 April 21st 10 03:40 AM
Copy contents of Find (Find and Replace) rob_bob Excel Discussion (Misc queries) 0 March 26th 09 11:01 PM
FIND AND COPY Judd Jones[_2_] Excel Programming 5 December 29th 04 08:36 PM
Find a day and copy Carlitos Excel Programming 1 June 23rd 04 02:12 AM
Find and Copy ? Robert Gillard Excel Programming 1 October 7th 03 02:35 AM


All times are GMT +1. The time now is 03:36 AM.

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

About Us

"It's about Microsoft Excel"