Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Do Not AutoFilter If Data Does Not Exist

  1. #11
    Thanks very much Admin. I am running the code exactly as below with today's date in column 'T' but when filtered column 'T' is not shown

    Code:
    Sub todaysdels()
    
     Dim rngFilter   As Range
    Dim dDate       As Date
    
    dDate = Date
    
    Set rngFilter = Range("a2:z" & Range("a" & Rows.Count).End(xlUp).Row)
    
    If Application.WorksheetFunction.CountIf(rngFilter.Columns(20), dDate) Then
         rngFilter.AutoFilter field:=20, Criteria1:=dDate
    Else
        MsgBox "No delivery for today!", vbOKOnly
    End If
        
    End Sub

  2. #12
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Here is screenshot of what I got.

    Untitled.jpg
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #13
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Try this one attached. Code below....

    I have changed the formula used in Column T. This is working at my side....

    Code:
    Option Explicit
    
    Sub FilterToday()
    
        FilterForDate Date
        
    End Sub
    
    Sub FilterTomorrow()
    
        FilterForDate CDate(Date + 1)
        
    End Sub
    Sub FilterForDate(dDate As Date)
        
        With Worksheets("test")
            .Range("A2").AutoFilter field:=20, Criteria1:=dDate
            If .Range("T3:T1000").Find(dDate, , xlValues) Is Nothing Then
                MsgBox "No delivery for today!", vbOKOnly
            End If
        End With
        
    End Sub
    Attached Files Attached Files
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  4. #14
    Thanks Both for your help. The strangest thing, I pasted the code into the version I use at work and the sheet works fine. Only problem is I have 4 sheets for 4 different customers. Much the same but some solumn info different. I tried to use the same code to filter todays deliveries on another sheet and it doesnt work. The delivery date it in column 16 this time so I changed the code but nothing shows once filtered. Any ideas where I am going wrong?

    Code:
    Sub todaysdels()
    
    Set rngFilter = Range("a2:P400" & Range("a" & Rows.Count).End(xlUp).Row)
    
    dDate = Date
    
    If Application.WorksheetFunction.CountIf(rngFilter.Columns(16), dDate) Then
         rngFilter.AutoFilter field:=16, Criteria1:=dDate
    Else
        MsgBox "There are no delivery for today!", vbOKOnly
    End If
       
    End Sub

  5. #15
    Thanks All. Now works brilliant! The code was perfect it was the cell formate giving me trouble Cheers

Similar Threads

  1. Replies: 2
    Last Post: 09-24-2012, 11:19 PM
  2. Checking Table Exist in Access Database or Not
    By littleiitin in forum Excel and VBA Tips and Tricks
    Replies: 1
    Last Post: 11-16-2011, 04:32 PM
  3. AutoFilter by Multi Color
    By Admin in forum Download Center
    Replies: 0
    Last Post: 09-08-2011, 07:17 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •