My code for a filter isn't working and i'm not sure why;
I'm trying to apply a filter to show 2 things in the same column
when i run the code, nothing appears.![]()
Please Login or Register to view this content.
My code for a filter isn't working and i'm not sure why;
I'm trying to apply a filter to show 2 things in the same column
when i run the code, nothing appears.![]()
Please Login or Register to view this content.
Last edited by kenadams378; 08-13-2012 at 05:29 AM.
slt,
try to use this code:
Worksheets("Sheet1").cells.AutoFilter Field:=2, Criteria1:="=GBPMORCA", Operator:=xlOr, Criteria2:="=GBPMOECA"
or
Worksheets("Sheet1").cells.AutoFilter 2,"GBPMORCA",xlor,"GBPMOECA"
My sheet just remains blank,
This is the whole code which opens the file, applies the filter, copies the data to another sheet.
![]()
Please Login or Register to view this content.
Can you attach the sample?
If I have helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Can't file it over 30mb.
The workbook has the following sheets;
Start
Original Morca
Orignal Moeca
S29 Data
Full code as follows;
![]()
Please Login or Register to view this content.
Bonjour,
I don't know data in your spreatsheet. but you can follow structure below:
Worksheet("sheet1").range("region for autofilter..eg A1:D65536...").Autofiler, Field:=???, Criteria1:="=GBPMORCA", Operator:=xlOr, Criteria2:="=GBPMOECA"
Field : is a number, that is location of column containing two values of criteria..GPMORCA and GBPMPECA
'Sorry I don't speak english well.'
Still doesn't work....
slt,
you can see an example below
if you want to copy data after autofilter. you have to put code lrow after
Worksheets("Sheet1").Cells.AutoFilter Field:=2, Criteria1:="=GBPMORCA", Operator:=xlOr, Criteria2:="=GBPMOECA"
lrow = Workbooks(FName).Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Have you tried without the "=" sign in front of the criteria? What error do you get?
I don't get an error, it just doesn't copy the data from the opened file into the tab to filter...
It will be good if you attach a sample file.
The smallest i can get the file down to is 11mb
Right, i have created 4 sheets which represent each tab in thew live workbook, this runs with the code listed above.
are you sure field 2 is the one you want? (none of the sample files contain the text you are filtering for which doesn't help us) you also did not fully qualify the source sheet. perhaps
![]()
Please Login or Register to view this content.
Last edited by JosephP; 08-10-2012 at 05:20 AM.
Josie
if at first you don't succeed try doing it the way your wife told you to
Sorry i should have edited the code, it is field 19 i require then selecting GBPMORCA & GBPMOECA
---------- Post added at 10:32 AM ---------- Previous post was at 10:28 AM ----------
I get the following error on this code
[code]
.AutoFilter Field:=19, Criteria1:="GBPMORCA", Operator:=xlOr, Criteria2:="GBPMOECA"
[/code
Autofilter method of range class failed
my bad-the filter range needs to be wider. replace this part
with![]()
Please Login or Register to view this content.
![]()
Please Login or Register to view this content.
I have got it to work now, just needed to extend the range of the copy before the filter.
Is there a way i can trim this macro down at all? Is it possible to use an array to open the files and copy data etc?
Trying to find the most efficient code to run this process.
you can use an array for the first two but the process is different for the third workbook.
How do i incorporate an array into the first two steps in the process?
Arrays confuse the life out of me?
![]()
Please Login or Register to view this content.
Many many thanks...
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks