Consulting

Page 1 of 3 1 2 3 LastLast
Results 1 to 20 of 52

Thread: Solved: filter criteria in active column

  1. #1

    Solved: filter criteria in active column

    hi, all
    can you help me?
    i have macro which filtered data based my condition in active column.
    but it sometimes doesnt works.

    pls. why ?

    f.e. if i have autofilter only in selected range of cell not in whole table it gives me an error -
    e:1004
    autofilter method of range class failed
    or
    sometimes it filter not in active column but in previous or next column
    [vba]Sub filter_show_BLANK()
    '
    ' Macro recorded 14.1.2009 by Vráblik
    '
    Columns(ActiveCell.Column).AutoFilter Field:=ActiveCell.Column, Criteria1:=""
    [/vba]
    my code:

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Presumably, because you are using the column number as the filter column offset. So, if you select column 5 only, you will be trying to filter on the 5th column of a one column selection - boom!
    ____________________________________________
    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

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    You are only selecting i column to filter on yet in the field you are targeting a second column!, use this:[VBA]Columns(ActiveCell.Column).AutoFilter Field:=1, Criteria1:=""[/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I am not sure why you don't just use 1, but you could try

    [vba]

    Sub filter_show_BLANK()
    '
    ' Macro recorded 14.1.2009 by Vráblik
    '
    Columns(ActiveCell.Column).AutoFilter Field:=Selection.Column - ActiveCell.Column + 1, Criteria1:=""
    End Sub
    [/vba]
    ____________________________________________
    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
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Quote Originally Posted by xld
    Presumably, because you are using the column number as the filter column offset. So, if you select column 5 only, you will be trying to filter on the 5th column of a one column selection - boom!
    Lol!, glad i didn't bother to run that line of code then, i'm using a laptop and that would have been a nasty accident!!!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Simon Lloyd
    Lol!, glad i didn't bother to run that line of code then, i'm using a laptop and that would have been a nasty accident!!!
    Yeah, he owes me a new, top of the range, quad processor laptop now!
    ____________________________________________
    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

  7. #7
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Quote Originally Posted by xld
    Yeah, he owes me a new, top of the range, quad processor laptop now!
    Funny, i forgot about the loss in translation, i was sure i said NASTY not EXPENSIVE!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Well, it was nasty when it happened, but these things have repurcussions.
    ____________________________________________
    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
    thx for all your advises but i dont have my solution, becaouse any of your code doesnt works as i want.
    Maybe i bad express my self.
    I want macro, which will always show only blanks cell, but only in column where i am - which is active, where is cursor.
    Doesnt matter if is freezet panes, if is autofilter only on part of table or anythning...
    can you help me with this?
    maybe som define range before it try filtering?

  10. #10
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Quote Originally Posted by Simon Lloyd
    You are only selecting i column to filter on yet in the field you are targeting a second column!, use this:[vba]Columns(ActiveCell.Column).AutoFilter Field:=1, Criteria1:=""[/vba]
    Whats wrong with this line?
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  11. #11
    Quote Originally Posted by Simon Lloyd
    Whats wrong with this line?
    this code filtered blanks but always in 1 column, but i need filtered column where i click, where is my cursor
    do you know what i mean?

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub filter_show_BLANK()
    '
    ' Macro recorded 14.1.2009 by Vráblik
    '
    Activesheet.UsedRange.AutoFilter Field:=ActiveCell.Column, Criteria1:=""
    End Sub
    [/vba]
    ____________________________________________
    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

  13. #13
    it gives me the same error

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Work for me.

    Do you have data in columns A forward?
    ____________________________________________
    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

  15. #15
    I dont want to have always data in column A
    look in atach.
    first - i click on cell I3
    second - run the macro which have to filtering column I and show me the blanks
    but maybe on next time i click in column G for example on cell G10 and i want to filtering column G

  16. #16
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    I suspect the fault is that filters are not being turned off before you click elsewhere.
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  17. #17
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    No attachment!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  18. #18
    one more time, atach
    i can not upload it

  19. #19
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub filter_show_BLANK()
    '
    ' Macro recorded 14.1.2009 by Vráblik
    '
    With ActiveCell

    .CurrentRegion.Select
    .CurrentRegion.AutoFilter Field:=.Column - .CurrentRegion.Cells(1, 1).Column + 1, Criteria1:=""
    End With
    End Sub
    [/vba]
    ____________________________________________
    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

  20. #20
    ok
    how define in code, what i want
    so if i have more as one table but autofilter is turned on only for one table, maybe from column E to H and i click in H it will show me the blank cell in this column. Of course it will works only if is the autofilter turned on for this column

Posting Permissions

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