Macro to filter by date in cell

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try replacing the line Date1 = Sheets("All Years Data").Range("M1").Value with
Code:
Date1 = CLng(Sheets("All Years Data").Range("M1").Value)
Bye
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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