Hello,
Subtotal apparently only works for filtered data or manually hidden rows. I'd like to make a function in VBA that is basically just subtotal, but work for whatever might be hidden, rather than just rows.
This seems to work as a test
In this case, H15:K15 is a list of dates, and I want it to output the most recent visible date
The problem arises when I try to put this in the form of a function.
I'm sure I must have my formatting wrong to reference the parameter y.
I realize that even with the formatting correct, this might not function entirely as subtotal would since it only works for an input of a single range besides the mode of the subtotal, but for my current purposes it should work fine.
Does anyone know what I need to change in the formatting here and/or a better way to mimic subtotal functionality with the addition of ignoring values in hidden columns?
Thanks
Subtotal apparently only works for filtered data or manually hidden rows. I'd like to make a function in VBA that is basically just subtotal, but work for whatever might be hidden, rather than just rows.
This seems to work as a test
Code:
Sub subtest()
Dim cl As Range
Set cl = Range(Range("h15"), Range("k15")).SpecialCells(xlCellTypeVisible)
MsgBox WorksheetFunction.Subtotal(4, cl)
End Sub
The problem arises when I try to put this in the form of a function.
Code:
Function SubCol(x As Integer, y As Range)
Dim cl As Range
Set cl = Range(Range(y), Range(y).End(xlToRight)).SpecialCells(xlCellTypeVisible)
SubCol = WorksheetFunction.Subtotal(x, cl)
End Function
I realize that even with the formatting correct, this might not function entirely as subtotal would since it only works for an input of a single range besides the mode of the subtotal, but for my current purposes it should work fine.
Does anyone know what I need to change in the formatting here and/or a better way to mimic subtotal functionality with the addition of ignoring values in hidden columns?
Thanks
Last edited: