Auto filer to vba code

jim101

Board Regular
Joined
Mar 22, 2005
Messages
110
I am using the code below to auto filer data for items that have not been completed and are over 60 days old, where column A is blank and column C is <= 60 days ago.
This works but I am wanting to use a workbook open event to check this and if there are any rows that met this bring up a message box letting me know which rows it is, it would need to look at the data in sheet2 from A4 to the last thing in Column C, can this be done?
Thanks Using Excel 2003

Code:
 Sub NotComplete()
Dim FilterCriteria As String
 FilterCriteria = Date - 60
    Sheet2.Range("B3").AutoFilter
    Sheet2.Range("B3").AutoFilter Field:=3, Criteria1:="<=" & FilterCriteria, Operator:=xlAnd
    Sheet2.Range("B3").AutoFilter Field:=1, Criteria1:="="
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Code:
Private Sub Workbook_Open()
    Dim rng As Range, cell As Range, counter As Long, msg As String
    
    With Sheet2
        Sheet2.AutoFilterMode = False   'Turn off autofitering on Sheet2
        Set rng = .Range("C4", .Range("C" & Rows.Count).End(xlUp))
    End With
    
    Call NotComplete
    
    On Error Resume Next
        counter = rng.SpecialCells(xlCellTypeVisible).Cells.Count
    On Error GoTo 0
    If counter Then
        msg = "There are " & counter & " items over 60 days and incomplete." & vbLf & vbLf
        If NCount <= 15 Then
            For Each cell In rng.SpecialCells(xlCellTypeVisible)
                msg = msg & "Row " & cell.Row & vbLf
            Next cell
        End If
        MsgBox msg, vbExclamation, "Over 60 Days and Incomplete"
    Else
        MsgBox "All items over 60 days are complete.", vbInformation, "All Complete"
        Sheet2.AutoFilterMode = False   'Turn off autofitering on Sheet2
    End If

End Sub
 
Upvote 0
You're welcome. I noticed a typo in the code.

This line...
If NCount <= 15 Then

Should be this...
If counter <= 15 Then

This limits the max number of rows listed in the message box to 15 so that the message box height doesn't get crazy.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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