+ Reply to Thread
Results 1 to 1 of 1

Edit search code criteria and rank results

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-16-2013
    Location
    Los Angeles, USA
    MS-Off Ver
    Excel 2011
    Posts
    620

    Edit search code criteria and rank results

    I am currently using the following code to fill the list box lbSamDesc with the data in Column C on sheet EquipmentData where the adjacent B Column is blank. It then removes duplicates and alphabetizes the results.

    Private Sub FillList()
        Dim wsEquipment                As Worksheet
        Dim lLastRow                   As Long
        Dim n                          As Long
        Dim lIndex                     As Long
        Dim vDataIn
        Dim colData                    As Collection
        Dim vDataOut()
        
        Set wsEquipment = Worksheets("EquipmentData")
    
        Me.lbSamDesc.Clear
        With wsEquipment
            lLastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
            If lLastRow > 3 Then
                lIndex = 1
                ReDim vDataOut(1 To lLastRow - 2)
                Set colData = New Collection
                vDataIn = .Range("B3:C" & lLastRow).Value
                On Error Resume Next
                For n = 1 To UBound(vDataIn, 1)
                    If Len(vDataIn(n, 1)) = 0 Then
                        colData.Add vDataIn(n, 2), CStr(vDataIn(n, 2))
                        If Err.Number = 0 Then
                            vDataOut(lIndex) = vDataIn(n, 2)
                            lIndex = lIndex + 1
                        Else
                            Err.Clear
                        End If
                    End If
                Next n
    
                If lIndex > 1 Then
                    ReDim Preserve vDataOut(1 To lIndex - 1)
                    'Me.lbSamDesc.List = vDataOut
                    Me.lbSamDesc.List = BubbleSort(vDataOut)
                End If
            Else
                If .Cells(3, "B").Value = vbNullString Then Me.lbSamDesc.AddItem .Cells(3, "C").Value
            End If
        End With
    End Sub
    
    Public Function BubbleSort(Strings) As Variant
    
       Dim a                 As Long
       Dim e As Integer, f As Integer, g As Integer
    
       Dim i As String, j    As String
       Dim m() As String, n() As Variant
    
       e = 1
       n = Strings
       Do While e <> -1
    
          For a = LBound(Strings) To UBound(Strings) - 1
             i = n(a)
             j = n(a + 1)
             f = StrComp(i, j)
             If f <= 0 Then
                n(a) = i
                n(a + 1) = j
             Else
                n(a) = j
                n(a + 1) = i
                g = 1
             End If
          Next a
          If g = 1 Then
             e = 1
          Else
             e = -1
          End If
    
          g = 0
       Loop
       BubbleSort = n
    End Function
    I am trying to do something similar where rather than using the criteria of instances where adjacent Column B is blank, but rather it directly searches the contents of Column C with the text in text box 'ItemDescription'.
    I will assign this code to a command button, so when the user clicks it will display all cases where the text in ItemDescription finds a match in Column C (doesn't have to be an exact match, it could just match one of, or part of a word, or string of letters in a cell). The results should remove the duplicates, and then be ranked so the most likely item is at the top (so basically cells with the most amount of matching words or string of letters appear first).
    Thanks,
    James
    Last edited by Nitefox; 06-14-2014 at 04:12 PM.

+ 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. Show Search results in userform and edit
    By cruiser102 in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 12-21-2012, 07:57 PM
  2. [SOLVED] Coyping results in Run-TIme Error 424, Need help to edit code
    By rocksan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-02-2012, 12:08 AM
  3. Rank results only when they meet certain criteria
    By CompleteMadness in forum Excel General
    Replies: 2
    Last Post: 01-18-2012, 12:00 PM
  4. VBA Code to Search/Edit Data Populated by Userform
    By pjohnson9 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-06-2011, 04:25 PM
  5. Edit code to add extra criteria
    By duugg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2008, 11:34 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