VBA to filter and copy visible cells to another workbook

storemannequin

Board Regular
Joined
May 29, 2010
Messages
108
I'm trying to set up a code to filter the data in my activesheet and then copy the visible cells to a new workbook but keep getting debug areas in just this first portion of the code. Can anyone tell me how to adjust? thanks

Code:
Sub filter()
FR = Cells(Rows.Count, 1).End(xlUp).Row
Set WBA = ActiveSheet
Set WBD = Workbooks.Add(template:=xlWBATWorksheet)
Set rng = WBA.Cells(2, 1).Resize(FR - 1, 1)
 
    Cells(1, 1).autofilter
    ActiveSheet.Range("$A$1:A" & FR).autofilter Field:=2, Criteria1:=Array( _
        "DEXIS", "GENDEX", "IMGSCI", "KAVO", "P&C"), Operator:=xlFilterValues
 
rng.SpecialCells(xlCellTypeVisible).EntireRow.Copy Destination:=WBD.Sheets(1).Cells(2, 1)
 
 
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Maybe something like this...

Code:
[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] filter()

    [color=darkblue]Dim[/color] WSA [color=darkblue]As[/color] Worksheet
    [color=darkblue]Dim[/color] WSD [color=darkblue]As[/color] Worksheet

    [color=darkblue]Set[/color] WSA = ActiveSheet
    
    [color=darkblue]Set[/color] WSD = Workbooks.Add(template:=xlWBATWorksheet).Worksheets(1)
    
    [color=darkblue]With[/color] WSA
        .AutoFilterMode = [color=darkblue]False[/color]
        .Cells(1, 1).AutoFilter
        [color=darkblue]With[/color] .AutoFilter.Range
            .AutoFilter Field:=2, Criteria1:=Array( _
                "DEXIS", "GENDEX", "IMGSCI", "KAVO", "P&C"), Operator:=xlFilterValues
            .Offset(1, 0).Copy Destination:=WSD.Cells(2, 1)
        [color=darkblue]End[/color] [color=darkblue]With[/color]
        .AutoFilterMode = [color=darkblue]False[/color]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
 
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,756
Members
452,940
Latest member
rootytrip

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