Results 1 to 5 of 5

Search a string and make a worksheet with the searched name will rows

Threaded View

  1. #1
    Registered User
    Join Date
    12-16-2014
    Location
    Bermuda
    MS-Off Ver
    2010
    Posts
    5

    Search a string and make a worksheet with the searched name will rows

    My requirements are simple. I have a huge worksheet with hundreds of rows and columns. I need to search a string or a part-of-the string, copy all rows which contain that part-of-string to a new worksheet and name the worksheet as the name of the string or sub-string.
    I tried the following code:
    Sub try()
    
        Dim strLastRow As String
        Dim rngC As Range
        Dim strToFind As String, FirstAddress As String
        Dim MySheetName As String
        Dim wSht As Worksheet
        Dim wSht1 As Worksheet
        Dim rngtest As String
        Application.ScreenUpdating = False
        strToFind = InputBox("Enter the STring to find")
            
        Set wSht = Worksheets("Sheet2")
            
        With ActiveSheet.Range("B1:B2000")
            Set rngC = .Find(what:=strToFind, LookAt:=xlPart)
                If Not rngC Is Nothing Then
                    FirstAddress = rngC.Address
                    Do
                        strLastRow = Worksheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Row + 1
                        rngC.EntireRow.Copy wSht.Cells(strLastRow, 1)
                        Set rngC = .FindNext(rngC)
                    Loop While Not rngC Is Nothing And rngC.Address <> FirstAddress
                End If
        End With
        On Error Resume Next
        MySheetName = strToFind
        Worksheets(MySheetName).Delete
        Err.Clear
        Application.DisplayAlerts = True
        Worksheets.Add.Name = MySheetName
        
        Sheets("Sheet2").Range("A1:B2000").Copy
        Sheets(MySheetName).Activate
        Range("A1").Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
        
        Sheets("Sheet2").Cells.ClearContents
            
        MsgBox ("Finished")
        
    End Sub
    The code works in excel 2010 but does not work in 2007. And it does not work for parts of string.
    My columns are like this_midas_2050, that_midas_2040 etc.
    I need to seach for midas in the worksheet and create a worksheet named midas.
    Thanks a lot in advance
    Last edited by purvamitra; 03-22-2015 at 10:02 AM.

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] Macro to search all sheets and return corresponding rows of searched value
    By amar05 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-19-2013, 01:56 AM
  3. make searched at combobox
    By bskaa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-30-2013, 09:13 AM
  4. [SOLVED] Macro to search a string, then search above for another one and copy the rows between them
    By DarKDjinni in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-20-2012, 09:36 PM
  5. Filtering rows in a column based on a string value search in excel worksheet.
    By Lifeseeker in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2012, 01:58 PM

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