+ Reply to Thread
Results 1 to 11 of 11

Search text in worksheets + copy to new sheet

Hybrid View

stonegwene Search text in worksheets +... 07-01-2011, 11:12 AM
Leith Ross Re: Search text in worksheets... 07-01-2011, 11:28 AM
stonegwene Re: Search text in worksheets... 07-01-2011, 11:30 AM
Leith Ross Re: Search text in worksheets... 07-01-2011, 11:35 AM
stonegwene Re: Search text in worksheets... 07-01-2011, 11:40 AM
Leith Ross Re: Search text in worksheets... 07-01-2011, 11:45 AM
stonegwene Re: Search text in worksheets... 07-01-2011, 11:55 AM
Leith Ross Re: Search text in worksheets... 07-01-2011, 11:58 AM
Leith Ross Re: Search text in worksheets... 07-01-2011, 12:39 PM
stonegwene Re: Search text in worksheets... 07-01-2011, 01:02 PM
vadenball Re: Search text in worksheets... 04-23-2012, 02:21 PM
  1. #1
    Registered User
    Join Date
    06-10-2011
    Location
    new york
    MS-Off Ver
    Excel 2010
    Posts
    12

    Search text in worksheets + copy to new sheet

    Hey,

    I've tried searching for an answer to my query but nothing quite works / fits - and I'm not really familiar enough with VBA to edit it enough to make it work.

    I have a workbook of many worksheets. Worksheet 1 has a list of names, with a header in row 1 "List", and below it are about 70 rows of alphanumeric one word text. I need to search all the other worksheets (worksheet 2 to the last worksheet) to see if any of those names in worksheet 1 appear. All the worksheets are formatted: column a + b + c + d contain data, row 1 is a header. In worksheet 2 onwards the alphanumeric one word text would appear in a text string in a cell. If they appear, I need to copy the entire row it was found in AND the title of the worksheet it was found in to a new worksheet.

    Attached is a template worksheet.

    Thanks!!
    Attached Files Attached Files
    Last edited by stonegwene; 07-01-2011 at 01:02 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Search text in worksheets + copy to new sheet

    Hello stonegwene,

    Are you searching for whole word matches or partial matches as well?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-10-2011
    Location
    new york
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search text in worksheets + copy to new sheet

    Whole word matches. If in worksheet 1, it says "AAAA" I need to only find "AAAA" in the other worksheets

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Search text in worksheets + copy to new sheet

    Hello ,

    If your example is true to the original data then a whole word match will not work with the example below:
    Name_Symbol=AAAA random info after
    The reason is a whole word match expects the word to have a space before and after the word unless it is the first or last word in the string.

  5. #5
    Registered User
    Join Date
    06-10-2011
    Location
    new york
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search text in worksheets + copy to new sheet

    Hmm.. that's fine - I can change the master list in sheet 1 to be "Name_Symbol=AAAA" then search for that string in the subsequent worksheets as they have a space "Name_Symol=AAAA [space] random info"

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Search text in worksheets + copy to new sheet

    Hello stonegwene,

    Using a partial match, I can set the macro to add an equal (=) in front of the AAAA and a space after it. But this would work only if the format were always =AAAA .

  7. #7
    Registered User
    Join Date
    06-10-2011
    Location
    new york
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search text in worksheets + copy to new sheet

    I can manually extract the "AAAA" or whatever the list name is, if somehow the row containing the cell of the partial match is copied over into the final worksheet, with the other details as specified above

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Search text in worksheets + copy to new sheet

    Hello stonegwene,

    Okay, I can do that for you.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Search text in worksheets + copy to new sheet

    Hello stonegwene,

    This macro has been attached to a button on "Sheet1". The attached workbook has the macro and button added.
    'Thread: http://www.excelforum.com/excel-programming/782555-search-text-in-worksheets-copy-to-new-sheet.html
    'Poster: Stonegwene
    'Written July 1, 2011
    'Author: Leith Ross
    
    Sub SearchForData()
    
      Dim C As Long
      Dim Cell As Range
      Dim ListWks As Worksheet
      Dim OutWks As Worksheet
      Dim R As Long
      Dim Rng As Range
      Dim SearchRng As Range
      Dim Wks As Worksheet
      
        Set ListWks = Worksheets("Sheet1")
        Set OutWks = Worksheets("Output")
        
        Set Rng = ListWks.Range("A1").CurrentRegion
        
          R = OutWks.Range("A1").CurrentRegion.Rows.Count
          Set Rng = Intersect(Rng, Rng.Offset(1, 0))
        
          For Each Cell In Rng
            For Each Wks In Worksheets
              C = Wks.UsedRange.Columns.Count
              Select Case LCase(Wks.Name)
                Case Is = "sheet1", "output"
                  'Do nothing skip these sheets
                Case Else
                  Set SearchRng = Wks.Cells.Find(Cell.Value, , xlValues, xlPart, xlByRows, xlNext, False)
                  If Not SearchRng Is Nothing Then
                     OutWks.Range("A1").Offset(R, 0) = Wks.Name
                     Set SearchRng = SearchRng.Parent.Cells(SearchRng.Row, 1).Resize(1, C)
                     SearchRng.Copy OutWks.Range("A1").Offset(R, 1).Resize(1, C)
                     R = R + 1
                  End If
              End Select
            Next Wks
          Next Cell
          
    End Sub
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    06-10-2011
    Location
    new york
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search text in worksheets + copy to new sheet

    Thanks - worked perfectly !!!

  11. #11
    Registered User
    Join Date
    04-23-2012
    Location
    Washington, USA
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Search text in worksheets + copy to new sheet

    I'm working on a similar problem to this, but need to get all the values that match YYYY LLLL etc. This only seems to pull the first row that contains a cell with those characters. Any thoughts?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1