AUTOFILTER

verluc

Well-known Member
Joined
Mar 1, 2002
Messages
1,451
I have a sheet which I want to filter with a macro.
I want to filter on column 11 who has the number 1 in it.
I have made the following macro,but he gives
me an error.What is wrong?
Sub Filter()
Selection.AutoFilter Field:=14,Criteria1:="1"
End Sub
Many thanks
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
try this:
Sub autofilter()
Columns("K:K").Select
Selection.AutoFilter Field:=1, Criteria1:="1"
End Sub
 
Upvote 0
On 2002-04-12 01:57, robfo0 wrote:
try this:
Sub autofilter()
Columns("K:K").Select
Selection.AutoFilter Field:=1, Criteria1:="1"
End Sub
Many thanks.It works.
But how can I set back in the original when I have seen the autofilter?
 
Upvote 0
On 2002-04-12 02:08, robfo0 wrote:
just issue the :
Selection.AutoFilter
in your code again and it will turn off
May I ask you a further question about this autofilter.
When I have the autofilter,I want this to transfer to another sheet in an other workbook.
In this case,I want to copy and paste this autofilter from the active workbook to workbook A,sheet 2
Have you the possibility to give me a macro to do this automatickly?
Thanks in advance
 
Upvote 0
Sub autofilter()

currentworkbook = ActiveWorkbook.Name
currentsheet = ActiveSheet.Name

Columns("K:K").Select
Selection.autofilter Field:=1, Criteria1:="1"
Range("K1:" & Range("K65536").End(xlUp).Address).Copy
Workbooks("workbook A.xls").Sheets("Sheet 2").Range("A1").PasteSpecial

Workbooks(currentworkbook).Sheets(currentsheet).Activate
Selection.autofilter
End Sub


now this assumes you want to paste to workbook "workbook A.xls", sheet "Sheet 2", and range "A1". Also, it assumes both workbooks are already open. if you need to open or close it, just do a search on this board, or a search in the help of vb in excel and youll find it pretty easy. i hope i didnt make any mistakes in that, i didnt test it :)
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,085
Members
448,548
Latest member
harryls

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