+ Reply to Thread
Results 1 to 4 of 4

explain the FuzzyLookup function

Hybrid View

cjGod explain the FuzzyLookup... 02-22-2008, 06:04 AM
dominicb Good morning cjGod ...and... 02-22-2008, 06:12 AM
cjGod hi there, ya i gt the codes... 02-22-2008, 06:14 AM
cjGod Hi again, can someone help me... 02-24-2008, 09:52 PM
  1. #1
    Registered User
    Join Date
    02-22-2008
    Posts
    13

    explain the FuzzyLookup function

    Hello all, i am quite new to excel programming, there is a UDF that is quite useful to me and i have been figuring out for quite some time nw, manage to understand some part of the code, but still can't seem to manage to understand the big picture of how the function should be use on. Can someone please explain to me or give me a example on what kind of excel data arrangement this UDF is used for?? Thanks


    Public Function VFuzzyLookup_Phrase(Lookup_Phrase As String, Table_Array As Variant, Optional Col_Index_Num As Integer = 1)
    
    Application.Volatile False
    
    Dim dblBestMatch As Double
    
    Dim iRowBest    As Integer
    Dim dblMatch    As Double
    Dim iRow        As Integer
    Dim strTest     As String
    Dim strInput    As String
    
    Dim iStartCol   As Integer
    Dim iEndCol     As Integer
    Dim iOffset     As Integer
    
    If InStr(TypeName(Table_Array), "(") + InStr(1, TypeName(Table_Array), "Range", vbTextCompare) < 1 Then
        'Table_Array is not an array
         VFuzzyLookup_Phrase = "ERROR"
        Exit Function
    End If
    
    If InStr(1, TypeName(Table_Array), "Range", vbTextCompare) > 0 Then
       Table_Array = Table_Array.Value
    End If
    
    ' If you get a subscript-out-of-bounds error here, you're using a vector instead
    ' of the 2-dimensional array that is the default 'Value' property of an Excel range.
    
    iStartCol = LBound(Table_Array, 2)
    iEndCol = UBound(Table_Array, 2)
    iOffset = 1 - iStartCol
    
    
    Col_Index_Num = Col_Index_Num - iOffset
    
    If Col_Index_Num > iEndCol Or Col_Index_Num < iStartCol Then
        'Out-of-bounds
         VFuzzyLookup_Phrase = "ERROR2"
        Exit Function
    End If
    
    
    
        strInput = UCase(Lookup_Phrase)
    
        iRowBest = -1
        dblBestMatch = 0
    
        For iRow = LBound(Table_Array, 1) To UBound(Table_Array, 1)
    
            strTest = ""
            strTest = Table_Array(iRow, iStartCol)
    
            dblMatch = 0
            'dblMatch = MatchPhrase(strInput, strTest)    ' Consider coding up a  MatchPhrase_Express() function, with the preprocessing
                                                        ' (StripChars, Split) of strInput done here, rather than repeatedly
    
            If dblMatch = 1 Then ' Bail out on finding an exact match
                iRowBest = iRow
                Exit For
            End If
    
            If dblMatch > dblBestMatch Then
                dblBestMatch = dblMatch
                iRowBest = iRow
            End If
    
        Next iRow
    
    
        If iRowBest = -1 Then
            VFuzzyLookup_Phrase = "#NO MATCH"
            Exit Function
        End If
    
    
        VFuzzyLookup_Phrase = Table_Array(iRowBest, Col_Index_Num)
    
    
    
    End Function
    Last edited by dominicb; 02-22-2008 at 06:09 AM.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good morning cjGod

    ...and welcome to the forum!!

    Take a look here for the full code, and an explanation by the orignator :
    http://hairyears.livejournal.com/115867.html

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Registered User
    Join Date
    02-22-2008
    Posts
    13
    hi there,
    ya i gt the codes from the webby, but i can really seem to understand on what is the code is use on..How the informations will look like in the excel sheet for the code to work.

    Thanks

  4. #4
    Registered User
    Join Date
    02-22-2008
    Posts
    13
    Hi again, can someone help me with the codes?

+ 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