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

  • 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...
  • find many based on a certain criteria
    good evening, I hope someone can help me? I have a workbook sheet 2 contains lots of data.... I would like to be able to find anything on sheet...
  • 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...
  • 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#...
  • Text Format
    I have a sheet for user to keyin the data. The format of the data can be 451 / 1903, 0012 / 9908 or 00287 / 0099. The number after the "/" is...
  • Syntax errors
    Good Morning, Trying to compile a workbook, I keep getting a few errors. Here are the first two: [code=rich]Syntax Error: Function...
Top