+ Reply to Thread
Results 1 to 3 of 3

Sorting out with a search string

Hybrid View

  1. #1
    Registered User
    Join Date
    05-13-2015
    Location
    Bangalore
    MS-Off Ver
    2007
    Posts
    52

    Sorting out with a search string

    Dear All,

    I have an excel file as attached below. I have to create a filter for yellow coloured cells of column A, with which I should be able to copy all the rows that comes under that respective yellow coloured cells. For example if I give filter as "31MBA" for the first column of the "Input Sheet", the output should be as shown in the "Output Sheet" in a numerical sequence (i.e. starting with 31MBA001/1, 31MBA001/2..then succeeding with 31MBA002/1, 31MBA002/2...so on and so forth. As the list is exhaustive to type manually, I have stopped with limited results in "Output Sheet"). Appreciate any help, as it's taking ages to complete this manually. Awaiting reply.

    P.S: Please note that the original input sheet had more than 28000 rows. I had to chop down the rows due to the limitation on file size to upload.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Sorting out with a search string

    Sub test()
        Dim myAreas As Areas, r As Range, myID, SL As Object, i As Long
        Dim FilterVal As String
        FilterVal = Application.InputBox("Enter filter value", , "31MBA", , , , , 2)
        If FilterVal = "" Then Exit Sub
        Application.ScreenUpdating = False
        Set SL = CreateObject("System.Collections.SortedList")
        Set myAreas = Sheets("input sheet").Columns("b").SpecialCells(2).Areas
        For Each r In myAreas
            myID = r(0, 0).Value
            If UCase$(myID) Like UCase$(FilterVal) & "*" Then
                myID = GetSortVal(r(0, 0) & r.Row)
                Set SL(myID) = r.Offset(-1).Resize(r.Rows.Count + 1).EntireRow
            End If
        Next
        With Sheets("output sheet")
            .Cells.Clear
            For i = 0 To SL.Count - 1
                SL.GetByIndex(i).Copy .Range("a" & Rows.Count).End(xlUp)(2)
            Next
            .Rows(1).Delete
        End With
        Application.ScreenUpdating = True
    End Sub
    
    Function GetSortVal(txt As String) As String
        Dim i As Long, m As Object
        With CreateObject("VBScript.RegExp")
            .Global = True
            .Pattern = "\d+"
            If .test(txt) Then
                For i = .Execute(txt).Count - 1 To 0 Step -1
                    Set m = .Execute(txt)(i)
                    txt = Application.Replace(txt, m.firstindex + 1, m.Length, Format$(m.Value, "0000000000"))
                Next
            End If
        End With
        GetSortVal = txt
    End Function

  3. #3
    Registered User
    Join Date
    05-13-2015
    Location
    Bangalore
    MS-Off Ver
    2007
    Posts
    52

    Re: Sorting out with a search string

    Dear Jindon,

    You were, are and hopefully will be my savior all the time. Fantastic work. Couldn't believe my eyes after executing the code. God Bless

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Script to Search for a specific String then return cell values above that String-4
    By owensjb2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-03-2015, 01:28 AM
  2. [SOLVED] Script to Search for a specific String then return cell values above that String-3
    By owensjb2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-01-2015, 01:50 PM
  3. [SOLVED] Script to Search for a specific String then return cell values above that String-2
    By owensjb2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-01-2015, 01:00 PM
  4. [SOLVED] Script to Search for a specific String then return cell values above that String
    By owensjb2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-01-2015, 11:28 AM
  5. [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
  6. [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
  7. 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