Consulting

Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 21 to 40 of 52

Thread: Solved: filter criteria in active column

  1. #21
    yes this last code works for more as one table (but only in one is active autofilter), but if i have only one table - autofilter for whole table, i want to use the same macro...but here it filtering other column as i want. Not this, which is active.
    And little detail, it select range of table and after finishing macro it is still whole selected..
    but i think, that you are close to solution

  2. #22
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Worked for me in both/either.
    ____________________________________________
    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. #23
    yes, it will works for me too, if i create new fiel with 2 tables and i try it there. If i give filter on part of data, it works, if i will only one filter it works too.
    BUT, if i try it on my huge data with 6000 rows and 80 columns - there i have only one filter and there it filtering other column
    i don know why if it is working for new createt small file

  4. #24
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Using Simon's code. Works with 120 cols x 6500 rows.
    [vba]Private Sub CommandButton1_Click()
    If ActiveSheet.AutoFilterMode Then Cells.AutoFilter
    Columns(ActiveCell.Column).AutoFilter Field:=1, Criteria1:=""
    End Sub
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #25
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Are you saying that you have two tables and you have selected bith before filtering?
    ____________________________________________
    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

  6. #26
    Quote Originally Posted by xld
    Are you saying that you have two tables and you have selected bith before filtering?
    sorry, what do you mean with "bith"?

    in my huge DB i have data from column A to column BW
    from row 1 to row 4400.
    there are blank rows between data too
    i have freezen pan
    i have autofilter always turned on in line 3 from column A to BW

    i click in cell J8 and run macro
    result: select part of table (J4:O3709) - 3710 is blank row
    - filter applied in column A - criterium ""

  7. #27
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can't you post that workbook?
    ____________________________________________
    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

  8. #28
    i tried it but i can not change it to fake data
    it is huge
    and if i deleted all and give there only a few of date, it works good
    so i am cluelles

  9. #29
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try this
    [VBA]
    Private Sub CommandButton1_Click()
    On Error Resume Next
    ActiveSheet.ShowAllData
    Range("A3:BW5000").AutoFilter Field:=Selection.Column, Criteria1:="="
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #30
    no this doesnt works
    but in this my huge table works my old code:

    i will now call it "code 1"
    Columns(ActiveCell.Column).AutoFilter Field:=ActiveCell.Column, Criteria1:=""
    maybe is solution something like

    do code1
    and if it is error
    do code 2

    code 2
    will be
    With ActiveCell
       .CurrentRegion.Select
       .CurrentRegion.AutoFilter Field:=.Column - .CurrentRegion.Cells(1, 1).Column + 1, Criteria1:=""
    Criteria1:=""
        End With
    i tried it like this, but its no good because it does both codes

    Sub filter_show_BLANK()
    Columns(ActiveCell.Column).AutoFilter Field:=ActiveCell.Column, Criteria1:=""
     
       On Error Resume Next
     
        With ActiveCell
       .CurrentRegion.Select
       .CurrentRegion.AutoFilter Field:=.Column - .CurrentRegion.Cells(1, 1).Column + 1, Criteria1:=""
           Rem If ActiveSheet.AutoFilterMode Then Cells.AutoFilter
        Rem Columns(ActiveCell.Column).AutoFilter Field:=ActiveCell.Column, Criteria1:=""
        End With

  11. #31
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Does it produce the result you would be looking for in my attached example?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  12. #32
    yes i tried your atach. and it works, BUT,
    i need something, what will be universal for any possibility
    - for small table
    - for huge table
    - for devided table - where i have filter only on a part of data
    -for table in unit
    ...
    and i run the macro from toolbar..so it is not necessary to insert button

    and this your code doesnt works if you cancel the autofilter for whole table and aplly autofilter o only for few columns

  13. #33
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    -for table in unit
    What does this mean?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  14. #34
    sorry for my terrible english

    table, which is not devided to parts, where is autofilter for whole first line of one table

  15. #35
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [vba]
    Sub Filtering()
    Dim FiltRng As Range
    Dim Col As Long
    On Error Resume Next
    ActiveSheet.ShowAllData
    Set FiltRng = ActiveSheet.AutoFilter.Range
    Col = Selection.Column - FiltRng(0).Column
    If FiltRng.Columns.Count = 1 And Col = 0 Then Col = 1
    FiltRng.AutoFilter field:=Col, Criteria1:=""
    End Sub

    [/vba]
    Last edited by mdmackillop; 03-20-2009 at 07:28 AM. Reason: Typo fixed.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  16. #36
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Testing workbook upload used range A1:BZ4400

    My workbook below just has data in every cell in the above range, which is more than yours and is 919kb, therefore my suggestion is to zip yours and upload it (shouldn't be a problem) or export your code from the workbook and upload that and your workbook without the VBA code, then we can help you fully!
    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. #37
    uff, no it doesnt works

    and when i look at the code... i think if it will works it will cancel all criteria in filter...with command „show all“

    why i want this:
    i use this for my daily work. I work with many tables and i have macros (toolbar) to filtering data as i want. I want to quck filtering data. Sometimes i want to filtering based on more as one criterium in filter. So i click in column based on i want to filtering, run first macro, then i click in other column an run other macro. I adding many criteria to filtering(f.e. i have macros for: blanks, nonblaks, =NA, <>NA ....)

    i dont know what i have to do

  18. #38
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If you want to run successive filters then remove the ShowAllData line.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  19. #39
    yes, but it still doesnt works
    but i have other question to this code


    Columns(ActiveCell.Column).AutoFilter field:=ActiveCell.Column, Criteria1:=""

    why this code doesnt works for autofilter, which is doesnt use for all table but only for part of table. If i use this code for autofilter where is autofilter for whole table it works great, but if is table from A to W, but i have filter in first line only for B to D, so it doesnt works- It give criterium to the next column . WHY?
    In code is written "ActiveCell.Column" and this is always the cell where i am or?
    i dont understund it

  20. #40
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    For successive filters, try the attached
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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