Excel VBA Advanced Filter Problem

-1

I made a program in VBA to calculate the cost in my company. For this I used two connections to the Oracle database. What's strange is the fact that when I try to use the advanced filter manually, it works. However, when I try to use VBA (recorded through macro using the filter manually), it does not work.

Sub custo()

'atualizacao da data
For Each c In Worksheets("BD2").Range("B1:B152")
 If c.Value <> "MOV_DATMOV" Then
 c.Value = ">" & DateAdd("yyyy", -1, Date)
 Else
 c.Value = "MOV_DATMOV"
 End If
Next c

For Each d In Worksheets("BD2").Range("C1:C152")
 If d.Value <> "MOV_DATMOV" Then
 d.Value = "<" & Date
 Else
 d.Value = "MOV_DATMOV"
 End If
Next d

'filtro de todas as despesas
'desp 001
Sheets("BD1").Columns("J:T").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Sheets("BD2").Range("A1:C2"), CopyToRange:=Sheets("CP").Range("A2"), _
        Unique:=False

The spreadsheets I use in loops are:

    
asked by anonymous 27.02.2018 / 21:19

1 answer

0

Do a test after changing the range that contains the criteria for the data source worksheet:

change this line

CriteriaRange:=Sheets("BD2").Range("A1:C2")

for

CriteriaRange:=Sheets("BD1").Range("A1:C2")

Still, if you plan to paste the filtered data into the BD2

change

CopyToRange:=Range("A2")

for

CopyToRange:=Sheets("BD2").Range("A2")

If it does not work, I suggest you provide a sample of the data and the desired result.

    
28.02.2018 / 03:26