UDF as an alternative for the new FILTER function built-in for the Excel 365

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
Hey Excel Gurus,

How are you guys doing today? I need a big favor from you. I am using older version of Ms Excel and in it the newer FILTER function that works by default in Office 365 is missing. I was hoping if anyone can make a UDF that could work exactly same way as the original.

Thanks a lot and will appreciate..
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
If you mean you want a UDF that can spill automatically, then you're pretty much out of luck.
 
Upvote 0
If you mean you want a UDF that can spill automatically, then you're pretty much out of luck.

my original post did imply I needed an exact replica. However, still, could I get the functionality of it without the spill?

For instance the user fill down the UDF on cells where it is required. manually filling the cells instead of spill.

I want to type something in cell say A1, and the UDF shall go in cell B1:B50
If A1 = Sub

Then B1 = Substitue
B2 = Submarine
B3 = Water Submerge
B4 = Subside
etc

Lookup array belongs to a table in other sheet of the same workbook. Example where all the "Sub" and non sub values are listed.

Is possible?
 
Upvote 0
This should get you started:

Code:
Function FilterRange(InputRange As Range, FilterFor As Variant)
    Dim data
    data = InputRange.Value
    Dim x As Long
    Dim d As Object
    Set d = CreateObject("Scripting.Dictionary")
    For x = LBound(data) To UBound(data)
        If InStr(1, data(x, 1), FilterFor, vbTextCompare) <> 0 Then d(data(x, 1)) = Empty
    Next x
    If d.Count Then
        Dim outputArray()
        ReDim outputArray(1 To d.Count, 1 To 1)
        For x = 1 To d.Count
            outputArray(x, 1) = d.keys()(x - 1)
        Next x
        FilterRange = outputArray
    End If
End Function
 
Upvote 0
This should get you started:

Code:
Function FilterRange(InputRange As Range, FilterFor As Variant)
    Dim data
    data = InputRange.Value
    Dim x As Long
    Dim d As Object
    Set d = CreateObject("Scripting.Dictionary")
    For x = LBound(data) To UBound(data)
        If InStr(1, data(x, 1), FilterFor, vbTextCompare) <> 0 Then d(data(x, 1)) = Empty
    Next x
    If d.Count Then
        Dim outputArray()
        ReDim outputArray(1 To d.Count, 1 To 1)
        For x = 1 To d.Count
            outputArray(x, 1) = d.keys()(x - 1)
        Next x
        FilterRange = outputArray
    End If
End Function




I tested the above but I get some repetitions.

for instance my lookup array in Sheet2 is..


Substitue
Intersub
manly
substance



And the formula in B1 of Sheet1 is =FilterRange(Sheet2!A2:A5,$A$2), it is copied down and I type in Cell A2 = man

The result will be


manly
manly
manly

When A2 = sub



Substitue
Intersub
substance
substance

substance appearing twice and manly appearing thrice... am I doing something wrong?
 
Upvote 0
You need to array enter the formula into multiple cells at once as it returns an array. Or wrap it in an index function:

=INDEX(FilterRange(Sheet2!A2:A5,$A$2),ROW(A1))

for example.
 
Upvote 0
You need to array enter the formula into multiple cells at once as it returns an array. Or wrap it in an index function:

=INDEX(FilterRange(Sheet2!A2:A5,$A$2),ROW(A1))

for example.
Do you mean pressing Ctrl+Shift+Enter? I tried it but the results are the same. I am a novice excel user and would appreciate a working excel file as a demo which I can download if not much trouble to you please...
Thanks for your help thus far.
 
Upvote 0
The INDEX version I just posted doesn't require array-entry, but you will of course want to use an absolute range reference for the source data:

=INDEX(FilterRange(Sheet2!$A$2:$A$5,$A$2),ROW(A1))
 
Upvote 0
The INDEX version I just posted doesn't require array-entry, but you will of course want to use an absolute range reference for the source data:

=INDEX(FilterRange(Sheet2!$A$2:$A$5,$A$2),ROW(A1))
was getting reference error in the end of the filtered list... hence with iferror it is working 100%

=IFERROR(INDEX(FilterRange(Sheet2!$A$2:$A$10,$A$2),ROW(A1)),"")
 
Upvote 0
Looks like you are just dealing with a column of values so would this also work for you?
I've just done it on one sheet but you should be able to adapt to two if it meets your need.

VBA Code:
Function Fltr(col As Range, FilterFor As String)
  Fltr = Filter(Application.Transpose(col), FilterFor, True, vbTextCompare)
End Function

omairhe 2020-02-24 1.xlsm
ABCDE
1SubstituesubSubstitue
2IntersubIntersub
3manlysubstance
4substance 
5 
Sheet2
Cell Formulas
RangeFormula
E1:E5E1=IFERROR(INDEX(Fltr(A$1:A$4,C$1),ROWS(E$1:E1)),"")
 
Upvote 0

Forum statistics

Threads
1,216,113
Messages
6,128,903
Members
449,477
Latest member
panjongshing

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top