Store Results of Filter Function in vba

vba_pwning_me

New Member
Joined
Jan 11, 2022
Messages
4
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
I have been increasingly frustrated so hopefully someone can help me. I'm trying to run the Filter(proj_name, assign_to = Target.Address) function in vba and store the results in a variable but I keep getting Error 2015 on my debug.

The idea is that I would like to store the array subset returned from the Filter function in a variable. Depending on what items are listed in the array their cells would have a different fill color. Here's what I have so far:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range
    Dim SecCells As Variant
    
' The variable KeyCells contains the cells that will
    ' refer to column A on the Assignment Map tab .
    Set KeyCells = Range("assign_prsnl")
    
    SecCells = Application.Filter(proj_name, assign_to = Target.Address)

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
           Is Nothing Then
        
        For x = LBound(SecCells) To UBound(SecCells)
            Debug.Print SecCells
        Next x
End If
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi & welcome to MrExcel.
What are proj_name and assign_to?
 
Upvote 0
In that case try
VBA Code:
    SecCells = Evaluate("Filter(proj_name, assign_to =" & Target.Address & ")")
 
Upvote 0
VBA cannot handle array calculations of that sort, so you need to use Evaluate which will calculate the formula in xl.
 
Upvote 0
Interesting. Good to know. Thank you for your help, I really appreciate it!
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,746
Messages
6,126,647
Members
449,325
Latest member
Hardey6ix

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