Copy filtered data to another sheet using VBA

后端 未结 4 650
礼貌的吻别
礼貌的吻别 2020-11-28 16:20

I have two sheets. One has the complete data and the other is based on the filter applied on the first sheet.

Name of the data sheet : Data
Name of

4条回答
  •  隐瞒了意图╮
    2020-11-28 16:38

    When i need to copy data from filtered table i use range.SpecialCells(xlCellTypeVisible).copy. Where the range is range of all data (without a filter).

    Example:

    Sub copy()
         'source worksheet
         dim ws as Worksheet
         set ws = Application.Worksheets("Data")' set you source worksheet here
         dim data_end_row_number as Integer
         data_end_row_number = ws.Range("B3").End(XlDown).Row.Number
        'enable filter
        ws.Range("B2:F2").AutoFilter Field:=2, Criteria1:="hockey", VisibleDropDown:=True
        ws.Range("B3:F" & data_end_row_number).SpecialCells(xlCellTypeVisible).Copy
        Application.Worksheets("Hoky").Range("B3").Paste
        'You have to add headers to Hoky worksheet
    end sub
    

提交回复
热议问题