Filter VBA

Clock10816

New Member
Joined
Sep 27, 2023
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hello!

I would like to filter data from Sheet1 that includes a certain text inside an item code "Example1", and copy and paste the entire row into another sheet (Sheet2). I want to do this for Example2 as well and copy and paste the entire row into Sheet3. This needs to be copied and pasted and not an array.

1695839615139.png


Thank you!!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Even though your image shows your data floating in mid air, I'm assuming it starts in column A, with your headers in row 1.
Try the following on a copy of your workbook.
VBA Code:
Option Explicit
Sub Clock10816_Copy()
    Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
    Set ws1 = Worksheets("Sheet1")
    Set ws2 = Worksheets("Sheet2")
    Set ws3 = Worksheets("Sheet3")
    
    If ws1.AutoFilterMode Then ws1.AutoFilter.ShowAllData
    With ws1.Range("A1").CurrentRegion
        .AutoFilter 1, "*Example1*"
        If .SpecialCells(xlCellTypeVisible).Address <> .Rows(1).Address Then
            .Offset(1).Resize(.Rows.Count - 1).Copy ws2.Cells(Rows.Count, 1).End(xlUp).Offset(1)
            .AutoFilter
        End If
        .AutoFilter 1, "*Example2*"
        If .SpecialCells(xlCellTypeVisible).Address <> .Rows(1).Address Then
            .Offset(1).Resize(.Rows.Count - 1).Copy ws3.Cells(Rows.Count, 1).End(xlUp).Offset(1)
            .AutoFilter
        End If
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,176
Messages
6,123,470
Members
449,100
Latest member
sktz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top