+ Reply to Thread
Results 1 to 11 of 11

Change macro to filter Zero not Empty cells

Hybrid View

  1. #1
    Registered User
    Join Date
    11-11-2013
    Location
    hun
    MS-Off Ver
    Excel 2013
    Posts
    76

    Thumbs up Change macro to filter Zero not Empty cells

    Hello.

    I am having difficulties changing this macro.
    What it do:
    When i double click the target field, it hides all the rows which are empty.
    I would like to use it to filter out the rows that has 0 in it.

    Can somebody help me out with this please?



    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Row < 2 Or Target.Row > 4 Then Exit Sub
    If Intersect(Target, Range("P2:CD4")) Is Nothing Then Exit Sub
    Cancel = True
    Application.ScreenUpdating = False
    ActiveSheet.UsedRange.Columns(1).EntireRow.Hidden = False
    On Error Resume Next
    With Range("A1", Cells(Rows.Count, 1).End(xlUp))
    .Offset(4, Target.Column - 1).Resize(.Count - 4).SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
    End With
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Change macro to filter Zero not Empty cells

    Not sure what your code is doing.
    You can use the autofilter though to filter items that do not equal 0

    for example
        ActiveSheet.Range("$P$2:$P$4").AutoFilter Field:=1, Criteria1:="<>0", _
            Operator:=xlAnd

  3. #3
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Change macro to filter Zero not Empty cells

    .SpecialCells(xlCellTypeBlanks
    this line in the code selects the blanc cells.

    you need to change this in a code which selects 0.

    Maybe (it's a gues)

     .cells("0")
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  4. #4
    Registered User
    Join Date
    11-11-2013
    Location
    hun
    MS-Off Ver
    Excel 2013
    Posts
    76

    Re: Change macro to filter Zero not Empty cells

    hey guys.
    Thank you for your efforts.

    I think the global problem may be: the fields i want to filter don't have numbers in it, they have the formula: "=K5*$K$4-L5*$L$4" (adds up numbers by colors, enc... doesn't really m
    Unfortunetly non of your advises seem to work

    Dave's solution:

    ActiveSheet.Range("$J$2:$J$600").AutoFilter Field:=1, Criteria1:="<>0", _
    Operator:=xlAnd


    Nothing happens, shows everything, still...

    Tried to change to:

    ActiveSheet.Range("$J$2:$J$600").AutoFilter Field:=1, Criteria1:="<1", _
    Operator:=xlAnd


    Hides everything (there are matches in the xls)

    Oeldere's solution.

    Hides everything

  5. #5
    Registered User
    Join Date
    11-11-2013
    Location
    hun
    MS-Off Ver
    Excel 2013
    Posts
    76

    Re: Change macro to filter Zero not Empty cells

    Another solution what i use in my other XLS is:


    Sub hide_J()
    Application.ScreenUpdating = False

    Cells.Select
    Selection.EntireRow.Hidden = False


    With Worksheets("- Stock -")
    lrow = .Range("A" & .Rows.Count).End(xlUp).Row
    For i = 5 To lrow
    If .Range("J" & i).Value = "0" Then
    .Rows(i).Hidden = True

    End If
    Next i
    End With

    Application.ScreenUpdating = True

    End Sub


    The problem is that the debugger gives me error when running it highlighting the following area: " lrow ="

    If anyone could tell me what is the wrong with it, that would be highly appretiated

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Change macro to filter Zero not Empty cells

    Maybe:

    Sub Viktor86HUN()
    ActiveSheet.Range("$J$2:$J$600").AutoFilter 1, 0
    End Sub

  7. #7
    Registered User
    Join Date
    11-11-2013
    Location
    hun
    MS-Off Ver
    Excel 2013
    Posts
    76

    Re: Change macro to filter Zero not Empty cells

    Hi John.
    Thank you for checking
    The problem is the same, it hides everything.

    Looks like the fact that these cells don't have numbers in it, just a formula: "=K8*$K$4-L8*$L$4" causes the error, do you know any method to work around this problem?

  8. #8
    Registered User
    Join Date
    11-11-2013
    Location
    hun
    MS-Off Ver
    Excel 2013
    Posts
    76

    Re: Change macro to filter Zero not Empty cells

    ok i got it working, i had to save my document in office 97 format..
    just figured this function is doing no good to me.

    probably i will need a macro for it.

    The point is to: Don't show the Zeros

    Do you have any idea why this macro gives me the error for: " lrow =" please?
    Sub hide_J()
    Application.ScreenUpdating = False

    Cells.Select
    Selection.EntireRow.Hidden = False


    With Worksheets("- Stock -")
    lrow = .Range("A" & .Rows.Count).End(xlUp).Row
    For i = 5 To lrow
    If .Range("J" & i).Value = "0" Then
    .Rows(i).Hidden = True

    End If
    Next i
    End With

    Application.ScreenUpdating = True

    End Sub

  9. #9
    Registered User
    Join Date
    11-11-2013
    Location
    hun
    MS-Off Ver
    Excel 2013
    Posts
    76

    Re: Change macro to filter Zero not Empty cells

    What i realized so far, by your response is that if i find the right format for these 2 lines, it could and should work

    With Range("A1", Cells(Rows.Count, 1).End(xlUp))
    .Offset(4, Target.Column - 1).Resize(.Count - 4).SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Filter uniques and ignore empty cells
    By Tony Valko in forum Excel Programming / VBA / Macros
    Replies: 39
    Last Post: 12-30-2013, 10:08 PM
  2. MACRO to empty a range of cells based on whether specified cell is empty
    By TBJV in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2013, 10:35 PM
  3. Using filter when the collumn contains empty cells
    By Bandini in forum Excel General
    Replies: 2
    Last Post: 04-25-2012, 09:13 AM
  4. Replies: 0
    Last Post: 08-10-2005, 12:05 PM
  5. macro to colour empty cells (cells not recognized as empty)
    By Gerben in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2005, 11:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1