Results 1 to 9 of 9

Transform User Defined Function to Sub (Filter Partial Concatenated Match) SOS

Threaded View

  1. #1
    Forum Contributor
    Join Date
    01-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    263

    Transform User Defined Function to Sub (Filter Partial Concatenated Match) SOS

    Hello,

    I'm running in circles. I've built this dashboard over a bunch of concatenated SKU placed in column. Each string vary the number of substrings, but every code has 34 lenght. A great human being also from this community helped me with this user defined function below. The code does exactly what I need: it loops through column "P" (SKUs) and search for partial matches within each code for every partial code that is referenced in another column.

    For instance, in this other column I have the partial codes: "005P" 039P" 0154P"

    The code will search for these 3 values within every substring of each cell of column "P", and then will return into another column ("M") the same array but showing only the match cases instead.


    So if I had:
    001M252P001C001T062D001E001S002993; 089M005P001C001T012D001E111S200326; 001M252P001C001T062D001E001S002993
    It'd only return
    89M005P001C001T012D001E111S200326;

    The script would be perfect if it didn't consume too much processing. The file became useless because it takes too long to update. I've tried everything I could think of, I simplified the formulas, switched every vlookup for index, tried to be the less redundant as possible, but it's still too slow.

    The way it is right now, I have these listboxes that will trigger a true/false statement that populates the reference column for the partial codes. The listboxes are set to trigger manual calculation as a band-aid, and when the user is done selecting the filters he presses a "update button" that turn calculation back to automatic. This band-aid is due to the fact that I assumed a conflict was happening when clicking the listbox and the user function would update at the same time the column is being populated.
    My guess is that using a sub code could be more efficient and maybe save me sometime. Right now it takes about 15-20 min to update every time. If I could take it down to 5 min I'd be glad already.

    Anyone has an opinion on this?

    Function InstanceCount(ByVal StringToSearch As String, ByVal StringToFind As String) As Long
        If Len(StringToFind) Then
            InstanceCount = UBound(Split(StringToSearch, StringToFind))
        End If
    End Function
    
    Function FindandCopy(origData As Range) As String
    
    Dim i As Long
    Dim c As Range
    Dim results As String
    
    For Each c In Worksheets("Engine I").Range("G4:G121")
        
        If InstanceCount(origData, c.Value) > 0 Then
            
            For i = 1 To CLng(InstanceCount(origData, c.Value))
                results = Mid(origData, (InStr(origData, c.Value) - 0), 34) & "; " & results
            Next
        End If
        FindandCopy = results
    Next c
    
    End Function
    Last edited by therealdees; 05-10-2021 at 11:24 AM.
    Pedro.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] User Defined function for comparing 2 array and return approximate match
    By menonarun in forum Excel - New Users/Basics
    Replies: 9
    Last Post: 05-13-2018, 01:09 AM
  2. User defined MATCH-INDEX function in VBA
    By SymMacro in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2016, 05:44 PM
  3. Replies: 1
    Last Post: 07-19-2014, 06:29 AM
  4. [SOLVED] User Defined Function To Add A Zero In A Concatenated Formula
    By BanburyS in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-29-2012, 02:23 AM
  5. How to write user defined function for Index and Match
    By spybug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-24-2012, 05:20 AM
  6. Creating a deeply nested IF MATCH user defined function
    By rrbest in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2011, 01:23 PM
  7. User Defined Function using Sumifs, Offset, Match and CountA
    By PeterW2020 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-29-2011, 02:29 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