VBA / AutoFilter Based on Cell Value

richardtims

New Member
Joined
Jun 25, 2018
Messages
31
Hello,

I have tried searching for a solution for my problem within the forums, but have been unsuccessful. I hope that this is not a duplicate thread, but if so, please let me know.

I am still pretty new to VBA and hopefully this is not too much of a Rookie question. I am trying to set an auto filter to filter out a specific date that would be a value in cell Z1 on the active worksheet. I have been playing around with it but can get it to actually work. The part that I need to replace is the "8/30/2018" portion of the code. It needs to be the date that is in cell Z1. Please let me know if you have a solution. Thanks.
Rich (BB code):
   ActiveSheet.Range("$A$1:$Z$382774").AutoFilter Field:=6, Operator:= _
        xlFilterValues, Criteria2:=Array(2, "8/30/2018")
 
First of all the code needs to match exactly the format of the cells (as I have already stated in 2 posts) not what you see in the autofilter.

Can you please copy and paste your current code in the thread as you did in post number 4 as we cannot copy the code from an image for testing.

Btw, from your image it looks like your date format is m/d/yyyy hhhh not m/dd/yyyy hhhh. Can you please check this as per my previous post (post number 5).
 
Last edited:
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Here is the most recent code I have......
Rich (BB code):
Sub Macro2()
'
' Macro2 Macro
'
    Range("N3").Select
    Selection.Copy
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    Workbooks.Open Filename:= _
        "\\dtwess11\sch_fore\Stats - Daily & Weekly\2018 Call Duration Report_Vendor.xlsb"
    Sheets("Detail Data").Select
    Range("Z1").Select
    ActiveSheet.Paste
    Rows("1:1").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$X$1382774").AutoFilter 6, Format(Range("Z1"), "m/dd/yyyy")
    ActiveSheet.Range("$A$1:$X$1382774").AutoFilter Field:=1, Criteria1:=Array( _
        "CE ALO ALO Greensboro", "CW ALO ALO Greensboro", "CW ALO ALO Sarasota", _
        "FL ALO ALO Greensboro", "MW ALO ALO Greensboro", "MW ALO ALO Sarasota"), _
        Operator:=xlFilterValues
'
End Sub
 
Upvote 0
The error message reads "Run-time error '1004': Application-defined or object-defined error.
You would be getting that message with the code below because you are trying to filter a range bigger than an excel worksheet that only contains 1,048,576 rows, not the 1,382,774 you have in that code. :)

Capture5.JPG
.
 
Upvote 0
First, Can I go hide in a hole, LOL. I can't believe I didn't see that. I am still getting an error message however, but it is different this time. It is "AutoFilter method of Range class failed", but it is still at the same line.
 
Upvote 0
Have you changed your format in your code to exactly match the format in the cells being filtered yet?
 
Upvote 0
Thanks to all who helped me with this. Problem is solved. After playing around with the formatting piece and lots of trial and error, it finally worked. Thanks!!!!!
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,627
Members
452,661
Latest member
Nonhle

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