![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Posts: 1,290
|
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 |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
try this:
Sub autofilter() Columns("K:K").Select Selection.AutoFilter Field:=1, Criteria1:="1" End Sub |
|
|
|
|
|
#3 | |
|
Board Regular
Join Date: Mar 2002
Posts: 1,290
|
Quote:
But how can I set back in the original when I have seen the autofilter? |
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
just issue the :
Selection.AutoFilter in your code again and it will turn off |
|
|
|
|
|
#5 | |
|
Board Regular
Join Date: Mar 2002
Posts: 1,290
|
Quote:
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 |
|
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|