SPILL RESULTS AS ARGUMENT FOR VBA FUNCTION

demariscal

New Member
Joined
Apr 22, 2016
Messages
6
I am trying to use the spilled results from a "FILTER" function in a spreadsheet and pass it as an argument to a VBA Function, but it is not working. Please help. Thank you.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Welcome to the Board!

Please show us what is being returned on your sheet, and the VBA code you are trying to use it in.
 
Upvote 0
I am trying to use the spilled results from a "FILTER" function in a spreadsheet and pass it as an argument to a VBA Function, but it is not working. Please help. Thank you.
Doing what Joe4 suggested would be helpful (keep it in mind for future questions you may ask), but if I can anticipate what your problem is... let's say you have this formula in cell A1...

=SEQUENCE(10)

and inside your VBA code you wanted to assign the number of elements in this spilled formula to a variable named HowMany, this is how you would reference the spilled range (note the # sign)...

HowMany = Range("A1#").Count
 
Upvote 0
Welcome to the Board!

Please show us what is being returned on your sheet, and the VBA code you are trying to use it in.
I am getting #VALUE.

VBA Code:
Public Function Interpolate(x As Double, Table As Variant, Optional NSel As Double = 2, Optional Way As String = "C", Optional iOrder As Single = 1) As Double
Dim cLast As Integer, rLast As Integer
Dim FirstVal As Integer, LastVal As Integer
Dim i As Long
i = 1

cLast = Table.Rows.Count
rLast = Table.Columns.Count

'Interpolation can be done at any order
'Select which way the table is set up as: Columns or Rrows
Select Case Way
    Case "C"
   
        If Table(1, 1) > Table(cLast, 1) Then
          
            'Descending
            Select Case x
                Case Is <= Table(cLast, 1): dem_Interpolate = Table(cLast, NSel)
                Case Is >= Table(1, 1): dem_Interpolate = Table(1, NSel)
                'Case Is < Table(1, 1): dem_Interpolate = "X too Small"
                'Case Is > Table(cLast, 1): dem_Interpolate = "X too High"
                Case Else
                    Do While x < Table(i, 1) And i < cLast
                        i = i + 1
                    Loop
                    dem_Interpolate = Table(i - 1, NSel) + (x ^ iOrder - Table(i - 1, 1) ^ iOrder) * _
                    (Table(i, NSel) - Table(i - 1, NSel)) / (Table(i, 1) ^ iOrder - Table(i - 1, 1) ^ iOrder)
            End Select
        Else
            Select Case x
                'Ascending
                Case Is <= Table(1, 1): dem_Interpolate = Table(1, NSel)
                Case Is >= Table(cLast, 1): dem_Interpolate = Table(cLast, NSel)
                'Case Is < Table(1, 1): dem_Interpolate = "X too Small"
                'Case Is > Table(cLast, 1): dem_Interpolate = "X too High"
                Case Else
                    Do While x > Table(i, 1) And i < cLast
                        i = i + 1
                    Loop
                    dem_Interpolate = Table(i - 1, NSel) + (x ^ iOrder - Table(i - 1, 1) ^ iOrder) * _
                    (Table(i, NSel) - Table(i - 1, NSel)) / (Table(i, 1) ^ iOrder - Table(i - 1, 1) ^ iOrder)
          
            End Select
    End If

Case "R"
    Select Case x
        Case Is <= Table(1, 1): dem_Interpolate = Table(NSel, 1)
        Case Is >= Table(1, rLast): dem_Interpolate = Table(NSel, rLast)
        'Case Is < Table(1, 1): dem_Interpolate = "X too Small"
        'Case Is > Table(1, rLast): dem_Interpolate = "X too High"
        Case Else
            Do While x > Table(1, i) And i < rLast
                i = i + 1
            Loop
            dem_Interpolate = Table(NSel, i - 1) + (x ^ iOrder - Table(1, i - 1) ^ iOrder) * _
            (Table(NSel, i) - Table(NSel, i - 1)) / (Table(1, i) ^ iOrder - Table(1, i - 1) ^ iOrder)
    End Select

End Select

End Function
 
Last edited by a moderator:
Upvote 0
When posting VBA code, please use Code Tags. It makes the code much more readable. See here for how: How to Post Your VBA Code
I updated the code in your previous post so it is more readable.

Can you please post us a sample of your data, where you are using this FILTER function?
And then show us where you are trying to use this function you have created?

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Which argument in your code is the spilled range from a FILTER function being assigned to... the Table argument? If so, a spilled range is not a table, it is just a range, nothing more. If not the Table argument, then which one?
 
Upvote 0
The argument "Table".
How are you referencing the spilled array from the FILTER function when you call your function on the worksheet? Also, it will be helpful for you to follow the advice Joe4 gave you above as it will make our job of helping you much easier.
 
Upvote 0
How are you referencing the spilled array from the FILTER function when you call your function on the worksheet? Also, it will be helpful for you to follow the advice Joe4 gave you above as it will make our job of helping you much easier.

=dem_Interpolate(D20,FILTER(RESULTS2!$N$4:$X$4723,RESULTS2!$P$4:$P$4723=$AB$15),6)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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