Unfilter a worksheet using vba

Stevep4

New Member
Joined
Aug 28, 2015
Messages
34
The below code opens up a separate excel file (Assort O") and filters the tab OO for what is in cell K2 in the HOME sheet of wkbk1. It then copies the filtered data and pastes into worksheet OOb in wkbk1. I would like to now how to unfilter the OO tab in wkbk2 after the data has been copied from it. The code works, but I can't figure out how to clear the filter from the OO tab.

VBA Code:
Sub CopyDataFromAssort()
Dim wkb1 As Workbook
Dim sht1 As Worksheet
Dim wkb2 As Workbook
Dim sht2 As Worksheet
Application.ScreenUpdating = False
Set wkb1 = ThisWorkbook
Set wkb2 = Workbooks.Open("S:\Merchandising\allocation\BUYER ASSORTMENT SHEETS\New Assortment Sheets\Assortment 2.0\Assort OO.xlsx")
Set sht1 = wkb1.Sheets("OOb")
Set sht2 = wkb2.Sheets("OO")
Set sht3 = wkb1.Sheets("Home")
sht1.Range("A2:AF150000").ClearContents
sht2.Range("a1:R150000").AutoFilter Field:=1, Criteria1:=[sht3].[K2]
sht2.Cells.Copy
sht1.Range("A1").PasteSpecial xlPasteValues
'sht2.Cells.ShowAllData
Application.CutCopyMode = False
'wkb2.AutoFilter tried this, didn't work
wkb2.Close True
Application.ScreenUpdating = True
End Sub

Thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Take your pick.

VBA Code:
ws.ShowAllData

will clear all filters

VBA Code:
ws.AutoFilterMode = False

will remove the filter

Where ws is the relevant worksheet.
 
Upvote 0

Forum statistics

Threads
1,214,565
Messages
6,120,254
Members
448,952
Latest member
kjurney

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