autofilter method of range class failed

fernandomtzm

New Member
Joined
Dec 9, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have this code:
Dim sapconect, Manual As Boolean
Dim Carpeta As String
Dim Col As String
Dim Archivo As String
Dim ArchivoTrabajo As String
Dim Fecha As Date
Dim Criterios() As String
Dim ReporteSAP, TW As Workbook
Dim MacroTAB As Sheets
Dim UltimaLinea As Integer
Dim i As Integer

Sheets("Sheet1").Select
Cells.Select
Selection.AutoFilter
UltimaLinea = Cells(Rows.Count, "A").End(xlUp).Row
ActiveSheet.Range("$A$1:$O$" & UltimaLinea).AutoFilter Field:=4, Criteria1:="SA"

'Add filter to select date until today

Manual = TW.Sheets("SAP Report Sample").Range("D14")
If Manual Then Col = "D" Else Col = "E"
ReDim Criterios(0 To 7)
For i = 0 To 7
Fecha = TW.Sheets("SAP Report Sample").Range(Col & "9").Value + i
If Fecha >= TW.Sheets("SAP Report Sample").Range(Col & "10").Value Then Exit For
Criterios(i) = Format(Fecha, "MM/DD/YYYY")

ActiveSheet.Range("$A$1:$O$" & UltimaLinea).AutoFilter Field:=12, Operator:= _
xlFilterValues, Criteria2:=Array(2, Criterios(0), 2, Criterios(1), 2, Criterios(2), _
2, Criterios(3), 2, Criterios(4), 2, Criterios(5), 2, Criterios(6), 2, Criterios(7))

'Criterios are dates i want to filter( are 7 Criterios of 7 days of week)

And appear the msge: error "1004" - autofilter method of range class failed in this code:

ActiveSheet.Range("$A$1:$O$" & UltimaLinea).AutoFilter Field:=12, Operator:= _
xlFilterValues, Criteria2:=Array(2, Criterios(0), 2, Criterios(1), 2, Criterios(2), _
2, Criterios(3), 2, Criterios(4), 2, Criterios(5), 2, Criterios(6), 2, Criterios(7))
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Are you trying to filter table 2? If not remover all the 2s in the Array that are not part of the Croteros array value.
 
Upvote 0
No, i just want to make a second filter on the same sheet.

The first one is this:
ActiveSheet.Range("$A$1:$O$" & UltimaLinea).AutoFilter Field:=4, Criteria1:="SA"

The second one is this: all in the same sheet

ActiveSheet.Range("$A$1:$O$" & UltimaLinea).AutoFilter Field:=12, Operator:= _
xlFilterValues, Criteria2:=Array(2, Criterios(0), 2, Criterios(1), 2, Criterios(2), _
2, Criterios(3), 2, Criterios(4), 2, Criterios(5), 2, Criterios(6), 2, Criterios(7))

all in the same sheet
 
Upvote 0
Are you trying to filter table 2? If not remover all the 2s in the Array that are not part of the Croteros array value.
No, i just want to make a second filter on the same sheet.

VBA Code:
 'The first one is this:
ActiveSheet.Range("$A$1:$O$" & UltimaLinea).AutoFilter Field:=4, Criteria1:="SA"

'The second one is this: all in the same sheet

[B]ActiveSheet.Range("$A$1:$O$" & UltimaLinea).AutoFilter Field:=12, Operator:= _
xlFilterValues, Criteria2:=Array(2, Criterios(0), 2, Criterios(1), 2, Criterios(2), _
2, Criterios(3), 2, Criterios(4), 2, Criterios(5), 2, Criterios(6), 2, Criterios(7))
[/B]
 
Upvote 0
You can disregard my post #2, I was misinterpreting the array. You are obviously filtering on a date.
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,212
Members
448,874
Latest member
b1step2far

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