Consulting

Results 1 to 9 of 9

Thread: How can I auto filter out "0:00" in excel 2010?

  1. #1

    How can I auto filter out "0:00" in excel 2010?

    Hi there,

    I am wondering if someone is able to assist me with the below code

    ActiveSheet.Range("$A$1:$Y$993").AutoFilter Field:=17, Criteria1:="0:00"

    Recording a macro that I found that I can filter in 0:00 with the above code however what I want in actuality is to have it unchecked.

    I tried the below code to no avail

    ActiveSheet.Range("$A$1:$Y$993").AutoFilter Field:=17, Criteria1:="<>0:00"

    Is there some other code that I can use?

    Thanks in advance.

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Is "0:00" a string value or an actual time? That is, does the formula bar show 12:00:00 AM?

    Presuming for the moment, legitimate times are entered and that there's a header row, I think you have data in columns A:Y. If that is correct, try using a helper column of sorts.

    In AA1, enter "Criteria" or another word that is not a field name.

    In AA2: =ISNA(MATCH(Q2,{0},0))

    Select Q1.

    Under the Data tab, choose Advanced (filter).

    Choose Filter the list, in-place

    If not already selected (and entered in the dialog), enter $Q$1:$Q$993 in List Range:

    Enter $AA$1:$AA$2 in Criteria range:

    Click the OK button.

    Hope that helps and here's an example from MSDN: http://support.microsoft.com/kb/183512

    Mark
    Last edited by GTO; 02-04-2015 at 11:21 PM. Reason: Oopsied...

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    it's quite likely that Column Q (or 17) of your table contains strings rather than numbers.

    if this is the case you can convert them into numbers by multiplying (or dividing) by 1. (or adding / subtracting 0.)

    below worked for me.

        With ActiveSheet
            .AutoFilterMode = False
            LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
            .Range("A" & .Rows.Count).Value = 1
            .Range("A" & .Rows.Count).Copy
            .Range("Q2:Q" & LastRow).PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply
            .Range("Q2:Q" & LastRow).NumberFormat = "h:mm"
            .Range("A1:Y" & LastRow).AutoFilter Field:=17, Criteria1:="<>00:00"
            .Range("A" & .Rows.Count).Clear
            .Range("A1").Activate
        End With
        Application.CutCopyMode = False
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Dates and times in VBA are always a challenge. I tend to force the format like so

        With ActiveSheet
        
            .Range("$A$1:$Y$993").AutoFilter Field:=17, Criteria1:="<>" & Format(0, .Cells(2, 17).NumberFormat)
        End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Thanks for all the suggestions but unfortunately none of them worked for me.

    To GTO

    the "0:00" is an actual formula in the cell where the value is being returned to.

    Not sure if that makes a difference or not. What is odd is if I do the reverse meaning write "ActiveSheet.Range("$A$1:$Y$993").AutoFilter Field:=17, Criteria1:="0:00""
    in the macro it does go and only select "0:00" in the auto filter so not sure why it should be treated differently when trying not to include it in a filter.

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    pls post your workbook here. you can replace/clear the sensitive data, if any.

    we only need colum Q values in order to test the code.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  7. #7
    Hi mancubus

    Please find the sheet attached
    Attached Files Attached Files

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

        With ActiveSheet
        
            .Range("$A$1:$Y$993").AutoFilter Field:=17, Criteria1:=">" & 1 / 10 ^ 10
        End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    Thanks xld

    That solutions works!!

Posting Permissions

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