Consulting

Results 1 to 4 of 4

Thread: VBA : Help on Filtered Range

  1. #1
    VBAX Regular
    Joined
    May 2016
    Posts
    14
    Location

    VBA : Help on Filtered Range

    Hi,
    I would need your expertise. In my macro, i am filtering by a fix range, but this range can change from another file that could be for instance 7600 lines instead of 7491 lines

    Is there a formula that I can write for the FILTER to filter until end of a selection, so if the quantity of line changes all the time i can have a dynamic and not static range ?

    Example :

    Range("O7491").Select
    Range(Selection, Selection.End(xlUp)).Select

    **this range could be more or less than 7491.

    Any help is appreciated as always,

    thanks
    Marty.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Not sure about your data layout on the worksheet, but

    Range("O1").CurrentRegion. Select

    will select the block of cells surrounding O1
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    May 2016
    Posts
    14
    Location
    Paul, yes this is part of the solution i was looking for, but it is more on the level of the FILTER.

    This formula for the filter is doing a selection of C1 to C12, but for my needs, when filtering, it could be more and less than 12 lines. Below formula is doing a selection of 12 lines, but would need the macro to do a selection based on the available lines of the selected columns that could be more and less that 12.

    Selection.AutoFilter
    ActiveSheet.Range("$C$1:$C$12").AutoFilter Field:=1

    Would you have an idea of the solution ?

    I appreciate your help.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Guess I'm not understanding the 'Selection' and filtering on a single column, with Field=1

    I usually do it something like this

    Option Explicit
    
    Sub Guess_01()
        Dim r As Range
        If ActiveSheet.AutoFilterMode Then ActiveSheet.FilterMode = False
        
        Set r = ActiveCell.EntireColumn.Cells(1, 1)
        Set r = Range(r, r.End(xlDown))
        
        r.AutoFilter
    End Sub

    Can you post an example WB showing what you're looking to do
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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