Article ID: 152215
Article Last Modified on 10/10/2006
Sub Filter_Return()
Sheets("sheet1").Select
Range("a1").Select
Selection.CurrentRegion.Select
row_count = Selection.Rows.Count - 1 ' Count the rows and
' subtract the header.
' The following three lines run an AutoFilter using "Cat" as the
' criteria for the first column and greater than 0 as the
' criteria for the second column.
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="Cat"
Selection.AutoFilter Field:=2, Criteria1:=">0"
matched_criteria = 0 ' Set variable to
' zero.
check_row = 0 ' Set variable to
' zero.
While Not IsEmpty(ActiveCell) ' Check to see if row
' height is zero.
ActiveCell.Offset(1, 0).Select
If ActiveCell.RowHeight = 0 Then
check_row = check_row + 1
Else
matched_criteria = matched_criteria + 1
End If
Wend
If row_count = check_row Then ' If these are equal,
' nothing was returned.
MsgBox "no matching data"
Else
MsgBox matched_criteria - 1 ' Display the number
' of records returned.
End If
End Sub
A1: Animal B1: In Stock C1: Price
A2: Dog B2: 1 C2: $1.00
A3: Cat B3: 2 C3: $2.00
A4: Dog B4: 3 C4: $3.00
A5: Cat B5: 4 C5: $4.00
A6: Bird B6: 5 C6: $5.00
=SUBTOTAL(3,C2:C6)
NOTE: The first argument for the Subtotal function is the function used to calculate the subtotal. The argument in this example uses the Count function (3) to calculate the subtotal.
Additional query words: copy paste visual basic sub total XL98 XL97 XL7 XL5 XL
Keywords: kbdtacode kbhowto kbprogramming KB152215