MikeMcCollister
Board Regular
- Joined
- May 6, 2020
- Messages
- 71
- Office Version
- 365
- Platform
- Windows
I am trying to do some advanced filtering so that I can sum some columns. My test code does not work. First when I try to set the criteria cell VBA just errors out. If I skip that and try to Call rangeTable.AdvancedFilter it does nothing.
I think that I am missing something fundamental. Any help will be appreciated.
Thanks,
Mike
VBA Code:
Function FilterTest(theMonth As String, category As String) As Variant
Dim rangeTable As Range
Dim rangeCriteria As Range
Dim rangeFiltered As Range
With Application.ThisWorkbook.Worksheets("Sheet1")
Set rangeTable = .Range("$A$5:$L$1001")
Set rangeCriteria = .Range("$A$3:$L$4")
End With
' set category to filter on
' !!! does not work
rangeCriteria(2, 4) = category
' set month to filter on
' !!! add code here
' does nothing
Call rangeTable.AdvancedFilter(xlFilterInPlace, rangeCriteria)
' FilterTest = columnE - columnG + columnH
' clear AdvancedFilter
' !!! add code here
FilterTest = 1.23
End Function
I think that I am missing something fundamental. Any help will be appreciated.
Thanks,
Mike