only copy certain columns and rows from filtered range

  • only copy certain columns and rows from filtered range


    after i filter a range, I would like only copy the filtered range from columns F:J and only the rows after the header and the first row (i.e., not the first two)...?


    presently i'm coping the whole filtered range and the code i'm using to filter (works well):


    Code
    Set rFilterHeadsar = Range("a1", Range("a1").End(xlToLeft))
    With wSheetAR
        .AutoFilterMode = False
        rFilterHeadsar.AutoFilter
        rFilterHeadsar.AutoFilter Field:=1, Criteria1:="=" & strCriteriaAR
        Set toCopyRangeAR = rFilterHeadsar.Offset(1, 0).SpecialCells(xlCellTypeVisible)
    End With
    
    
    toCopyRangeAR.Copy Sheets("mm").Range("A25")  'here is where i would like to only copy in columns F:J, rows after first two


    ...


    thank you.

  • Re: only copy certain columns and rows from filtered range


    Hi Mjschukas


    Thefollowing should get you over the line.



    I put some variables in and tested it to ensure it ran OK. If you want to do the same just put some data in Col A of a blank workbook and change the str variable to one of the filter criteria. I only copied from A to G, change to suit.


    Take care


    Smallman

  • Re: only copy certain columns and rows from filtered range


    works like a charm....thank you!


    here's my code:


    thank you...

  • Re: only copy certain columns and rows from filtered range


    thank you again...


    one more question, what do you think about using: Set sh = ActiveSheet vs naming the sheet explicitly
    (e.g., Set sh = Worksheets("sheet2").UsedRange)...?


    thank you.

  • Re: only copy certain columns and rows from filtered range


    If you use Active|Sheet you will need to have the actual sheet that you have the data on active, if you refer to the sheet in the code then you won't.


    This will not worrk anyway if sh is declared as a worksheet


    Code
    Set sh = Worksheets("sheet2").UsedRange)...?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!