Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Newbie: Find additional text strings

You got me???
Is there an "End If" following the statement?
Do you have more than on sheet selected when the code is run?

The following version eliminates the creation of the worksheet if
nothing is found. You might try it and see if the problem still occurs.
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html

Sub CopyFoundStuff()
'Modified by Jim Cone on August 31, 2006 to find multiple words.
Dim wksCopyTo As Excel.Worksheet
Dim wksCopyFrom As Excel.Worksheet
Dim rngToSearch As Excel.Range
Dim rngFound As Excel.Range
Dim rngFoundAll As Excel.Range
Dim rngCombined As Excel.Range
Dim strFirstAddress As String
Dim varWords As Variant
Dim lngN As Long

varWords = Array("This", "That", "Whatever")
Set wksCopyFrom = Sheets("Sheet1")
Set rngToSearch = wksCopyFrom.Columns("A")

For lngN = 0 To UBound(varWords)
Set rngFound = rngToSearch.Find(What:=varWords(lngN), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry " & varWords(lngN) & " was not found."
Else
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Application.Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
If rngCombined Is Nothing Then
Set rngCombined = rngFoundAll
Else
Set rngCombined = Application.Union(rngCombined, rngFoundAll)
End If
End If
Next 'lngN
If Not rngCombined Is Nothing Then
Set wksCopyTo = Worksheets.Add(Count:=1)
rngCombined.EntireRow.Copy wksCopyTo.Range("A2")
End If
End Sub
'----------------



"John Hughes"
wrote in message
Thank you Jim! It seems to be working except for the last line. The debugger
goes to this statement:

If Not rngCombined Is Nothing Then
rngCombined.EntireRow.Copy wksCopyTo.Range("A2")


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 replace numeric strings in larger text strings Mr Molio Excel Worksheet Functions 8 November 9th 11 05:17 PM
find multipule text strings within a cell The Rook[_2_] Excel Discussion (Misc queries) 1 December 1st 08 02:56 PM
How to find common strings of text then copy those rows elsewhere? energyzone Excel Worksheet Functions 6 April 20th 08 06:54 PM
How to find number of pairs of strings from list of strings? greg_overholt Excel Worksheet Functions 5 January 27th 06 10:42 PM
Adding additional rows in VBA based on character strings Mike Excel Programming 1 February 8th 05 06:22 PM


All times are GMT +1. The time now is 01:49 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"