Gringoire
Board Regular
- Joined
- Nov 18, 2016
- Messages
- 71
- Office Version
- 365
- Platform
- Windows
Hello everybody,
I have to obtain a sum from some filtered cells (see code below). Unfortunately the code below raises a 1004 error when the result of filtering operation is an empty range.
I would like to avoid using "On error..." procedures because it could mask some other unexpected error.
I would also like to avoid to use sumifs() instead of filters because I need to put multiple conditions on some columns and that needs a big amount of workaround code...
is there a way to verify the filtered range without raising an error if it is empty?
Statements like :
or
seems not working...
My code:
thanks.
I have to obtain a sum from some filtered cells (see code below). Unfortunately the code below raises a 1004 error when the result of filtering operation is an empty range.
I would like to avoid using "On error..." procedures because it could mask some other unexpected error.
I would also like to avoid to use sumifs() instead of filters because I need to put multiple conditions on some columns and that needs a big amount of workaround code...
is there a way to verify the filtered range without raising an error if it is empty?
Statements like :
VBA Code:
If Not (.SpecialCells(xlCellTypeVisible)) Is Nothing
VBA Code:
If IsError (.SpecialCells(xlCellTypeVisible))
My code:
VBA Code:
Function filteredsum()
Dim risultati(1 To 2)
With shRawData.ListObjects("TabRawData").DataBodyRange
If Not (.SpecialCells(xlCellTypeVisible)) Is Nothing Then
risultati(1) = WorksheetFunction.Sum(.Columns(RWC.valtot).SpecialCells(xlCellTypeVisible))
risultati(2) = WorksheetFunction.Sum(.Columns(RWC.qta).SpecialCells(xlCellTypeVisible))
Else
risultati(1) = 0
risultati(2) = 0
End If
End With
filteredsum = risultati
End Function
thanks.