autofilter of range problem

tomleitch

Board Regular
Joined
Jan 3, 2012
Messages
185
Hi,

Wondering if anyone can help with this....

I'm trying to make my code set up two filters on my sheet - the first is a date on column 39 (based on pre defined date dat minus 28days) and the second is to filter for containing not blank cells.

Code:
With Sheets("OPS PLANNER")
            .AutoFilterMode = False
                With .Range("A9:AT5010")
                     .AutoFilter
                     .AutoFilter Field:=39, Criteria1:="<=" & dat - 28
                     
                     .AutoFilter Field:=45, Criteria1:="<>"
                     
                End With

Exit Sub
It seems to run ok but for some reason is coming up with nothing even when there are results.

Probably something obvious! but can anyone help?

Thanks
Tom
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,690
Office Version
2019
Platform
Windows
Your second criteria translates to "doesn't equal". What are you trying to get it to do because "doesn't equal" doesn't equate.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
45,247
Office Version
365
Platform
Windows
Your second criteria translates to "doesn't equal". What are you trying to get it to do because "doesn't equal" doesn't equate.
Criteria1:="<>"
equates to "is not equal to blank", which is what the OP stated they want. If you record a macro to auto filter (Text Filter... -> Does not equal -> leave the top right box empty -> OK) the criteria is recorded as above.

Tom
If you change this line in your code does it help?
Rich (BB code):
.AutoFilter Field:=39, Criteria1:="<=" & CLng(dat - 28)
 

tomleitch

Board Regular
Joined
Jan 3, 2012
Messages
185
Morning, yep - that seemed to be what the problem was.

I have changed it to be 28 days older than today and it seems to work

Code:
dat = ">=" &  date - 28

With Sheets("OPS PLANNER")
            .AutoFilterMode = False
                With .Range("A9:AT5010")
                     .AutoFilter
                     .AutoFilter Field:=39, Criteria1:=dat
                     
                     .AutoFilter Field:=45, Criteria1:="<>"
                     
                End With
Thanks
Tom
 

tomleitch

Board Regular
Joined
Jan 3, 2012
Messages
185
Peter, just seen your reply - and thanks for your help.

I think I've kind of done a similar thing to you suggest?


Thanks
Tom
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
45,247
Office Version
365
Platform
Windows
Peter, just seen your reply - and thanks for your help.

I think I've kind of done a similar thing to you suggest?


Thanks
Tom
Your change doesn't work for me as I understand what you are trying to do, but if it is working for you, that's all that matters. :)
 

Watch MrExcel Video

Forum statistics

Threads
1,102,660
Messages
5,488,159
Members
407,628
Latest member
Faceless Judge

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top