Autofilter table depending on the date value from different sheet MACRO VBA

mark692

Board Regular
Hi sir as the title say, i want to filter a table depending on the value form different sheet


i have 2 sheets

Sheet 1 is where the cell is located with a date (Example cell is B1)

on

Sheet 2 i have a table with a column "DATE", i want to filter the column DATE, depending on the given date on sheet 1 B1


im using this code but i think its not working

ActiveSheet.ListObjects("Table8").Range.AutoFilter Field:=1, Criteria1:= range. B1
thanks in advance :)
 

Fluff

MrExcel MVP, Moderator
How about
Code:
ActiveSheet.ListObjects("Table8").Range.AutoFilter Field:=1, Criteria1:=Sheets("Sheet1").Range("B1")
 

mark692

Board Regular
i see, if the format is date, its not working but if i change the format to a value, it works, its not working if the criteria is on date format, :(
 

Fluff

MrExcel MVP, Moderator
If you are filtering on dates try
Code:
ActiveSheet.ListObjects("Table8").Range.AutoFilter Field:=1, Criteria1:=CDate(Sheets("Sheet1").Range("B1"))
or
Code:
ActiveSheet.ListObjects("Table8").Range.AutoFilter Field:=1, Criteria1:=Clng(Sheets("Sheet1").Range("B1"))
 

mark692

Board Regular
If you are filtering on dates try
Code:
ActiveSheet.ListObjects("Table8").Range.AutoFilter Field:=1, Criteria1:=CDate(Sheets("Sheet1").Range("B1"))
or
Code:
ActiveSheet.ListObjects("Table8").Range.AutoFilter Field:=1, Criteria1:=Clng(Sheets("Sheet1").Range("B1"))

hi sir it gives me error invalid procedure call or argument
 

Fluff

MrExcel MVP, Moderator
There is no reason why you would get that error on that line, if the code in post#2 did not give an error.
 

mark692

Board Regular
There is no reason why you would get that error on that line, if the code in post#2 did not give an error.

i get it now sir the error "invalid procedure call or argument" only appears when i use it on my laptop, but when im on my desktop computer, it works fine. thats weird :LOL:
 

Some videos you may like

This Week's Hot Topics

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
Top