Macro to filter by date in cell

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,054
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

Not sure what ive done wrong please help if you can.

I want a macro to filter based on a data in cell M1

But my current code hides all the cells can someone help me or give me a new code that works please?

thanks

Tony

my code

Code:
Sub Get_Todays_Data()
Application.ScreenUpdating = False
Date1 = Sheets("All Years Data").Range("M1").Value
Sheets("All Years Data").Select
Lastrow = Sheets("All Years Data").Cells(Rows.Count, "A").End(xlUp).Row
If Lastrow < 2 Then
Lastrow = 2
End If
Sheets("All Years Data").Select
Sheets("All Years Data").Range("$A1:$J1").AutoFilter
Sheets("All Years Data").Range("A1", "J" & Lastrow).AutoFilter Field:=3, Criteria1:="=" & Date1
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Anthony47

Well-known Member
Joined
Mar 29, 2006
Messages
2,829
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Try replacing the line Date1 = Sheets("All Years Data").Range("M1").Value with
Code:
Date1 = CLng(Sheets("All Years Data").Range("M1").Value)
Bye
 

Forum statistics

Threads
1,171,026
Messages
5,873,371
Members
432,976
Latest member
Manbjorngris

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
Top