Excel Advanced Filter - Macro - issue with finding the last cell

Clint123

New Member
Joined
Sep 18, 2013
Messages
10
Hi All,

First time using this forum so welcome all.

Just a question with my "Excel Advanced Filter - Macro" as below. Everything works fine

Issue: is the Range and that it changes "A4" will always be the first cell, however it may go from "A4:A6" or "A4:A333". Therefore, I need the Macro to take the last field etc.

MultipleSKU Macro
'
Sheets("EMEA - 12mth DEMD").Cells.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("A4:A12"), CopyToRange:=Range("F2:U2"), Unique:= _
False

End Sub

Thanks if anyone can help
 
Unfortunately, new error message Run-time error "1004": Application defined or object defined error

Sub MultipleSKU()
'
' MultipleSKU Macro
'




'
With Worksheets("Multiple SKU's")
Sheets("EMEA - 12mth DEMD").Cells.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("A4" & .Range("A" & Rows.Count).End(xlUp)), CopyToRange:=Range("F2:U2"), Unique:=False
End With




End Sub
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Which worksheet do you want to filter?

Which range on that worksheet has the data you want to filter?

Which worksheet is the criteria range on?

Which worksheet is the copy to range on?
 
Upvote 0
Unfortunately, new error message Run-time error "1004": Application defined or object defined error

Sub MultipleSKU()
'
' MultipleSKU Macro
'




'
With Worksheets("Multiple SKU's")
Sheets("EMEA - 12mth DEMD").Cells.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("A4" & .Range("A" & Rows.Count).End(xlUp)), CopyToRange:=Range("F2:U2"), Unique:=False
End With




End Sub
 
Upvote 0
Which worksheet do you want to filter? All of the data is in worksheet "EMEA - 12mth DEMD"

Which range on that worksheet has the data you want to filter? As above, we want to filter in the data in worksheet "EMEA - 12mth DEMD" and bring it into to show worksheet "Multiple SKU's"

Which worksheet is the criteria range on? "Multiple SKU's"

Which worksheet is the copy to range on?
"Multiple SKU's"

I hope that helps someone, "HELP ME" to solve this...
 
Upvote 0
Sorry, all the ranges, including the data, are on the same sheet 'Multiple SKU's'.

Why does the code refer to Sheets("EMEA - 12mth DEMD")?

By the way, you haven't said which range of data you want to filter - filtering the entire worksheet might not be a good idea, and in fact could be the cause of the error.
 
Upvote 0
No sorry, perhaps I wasnt clear,

The data sits on Sheet ("EMEA - 12mth DEMD")

So from the Sheet ("
Multiple SKU's') I go to advanced filter, "Copy to another location"

List range is taken from
Sheet ("EMEA - 12mth DEMD")

Criteria range is taken from
Sheet ("Multiple SKU's') as is Copy to.

Does that help?
 
Upvote 0
Try this, but I still think you would be better to specify the range you want to filter.
Code:
    With Worksheets("Multiple SKU's")
        Sheets("EMEA - 12mth DEMD").Cells.AdvancedFilter Action:=xlFilterCopy, _
                          CriteriaRange:=.Range("A4" & .Range("A" & Rows.Count).End(xlUp)), CopyToRange:=.Range("F2:U2"), Unique:=False
    End With
 
Last edited:
Upvote 0
You could upload it to somewhere like Box.net and then post a link.

By the way, did you try changing from Cells to the actual range you want to filter?

For example, and it's not a good example, this with filters the userd range on the 'EMEA' sheet.
Code:
With Worksheets("Multiple SKU's")
        Sheets("EMEA - 12mth DEMD").UsedRange.AdvancedFilter Action:=xlFilterCopy, _
                          CriteriaRange:=.Range("A4" & .Range("A" & Rows.Count).End(xlUp)), CopyToRange:=.Range("F2:U2"), Unique:=False
End With
The reason that this is a bad example is because UsedRange can't always be relied on.

It would be better if the range to be filter was stated explicitly.s
 
Upvote 0

Forum statistics

Threads
1,216,562
Messages
6,131,422
Members
449,651
Latest member
Jacobs22

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