Results 1 to 7 of 7

Search for string help

Threaded View

  1. #1
    Registered User
    Join Date
    03-31-2015
    Location
    Seattle, WA
    MS-Off Ver
    2007
    Posts
    2

    Search for string help

    I am trying to get this macro to search through column A to find all entries with a certain name (user input) and then copying and pasting each matching row to a different sheet in the work book. Here is what I have so far:

    Option Explicit
     Sub clear()
         Sheets("Table").Select
         Columns("A:S").EntireColumn.ClearContents
         Sheets("Summary").Select
         End Sub
    
    Sub SearchForString()
    
        Dim LSearchRow As String
         Dim LCopyToRow As Long
    Dim userinput As String
         
         userinput = InputBox(Prompt:="Enter name here.", _
              Title:="ENTER NAME", Default:="Name here")
      
         LSearchRow = 2
         
    
         LCopyToRow = 1
         
    
         While Len(Range("A" & CStr(LSearchRow)).Value) > 0
    
           
             If Range("A" & CStr(LSearchRow)).Value = userinput Then
    
                 Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
                 Selection.Copy
    
                 Sheets("Summary").Select
                 Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
                 ActiveSheet.Paste
                 LCopyToRow = LCopyToRow + 1
    
                 Sheets("Summary").Select
    
             End If
    
             LSearchRow = LSearchRow + 1
    
         Wend
    
         Application.CutCopyMode = False
         Range("b2").Select
    
         MsgBox "All matching data has been copied."
    
         Exit Sub
    
    
    
     End Sub
    This seems to do what I am intending, however, it only returns the very first match and does not search throughout the entire column. The sheet with the data is named "Table" and the sheet I am copying too is "Summary." Any help would be much appreciated!

    Here is an example of the data I am using:
    Tyler Barto 5 8. 7.50 .50 .50 7. 6.50 0 1326 0 222 1296. 521 204.00 80.
    Jake Parker 6 5. 1.70 .50 .50 4. .70 0 264 0 0 274. 137 377. 196. 61.
    Rob Carlton 7 5. 4. .50 .50 4. 3. 0 885 0 248 859.3 0 290 271. 89.
    Last edited by tschroder; 03-31-2015 at 04:22 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 09-11-2014, 10:59 AM
  2. [SOLVED] Vlookup, Match (Search or Find) partial string within string in a Cell
    By dluhut in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-28-2013, 12:40 PM
  3. Replies: 1
    Last Post: 09-20-2012, 03:22 PM
  4. [SOLVED] Search for string across header row, then search for another string down found column
    By TucsonJack in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-14-2012, 02:09 PM
  5. search a string withing a string : find / search hangs
    By itarnak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-24-2005, 11:05 AM

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