AutoFilter Excel VBA

0

I have a problem, when trying to make an autofilter in vba it is trying to filter the values I chose but it does not filter value, I searched a lot and found no explanation. The code is as follows:

Dim nomeArquivo As String
        Dim gd As Integer
        nomeArquivo = Left(ThisWorkbook.Name, (InStrRev(ThisWorkbook.Name, ".", -1, vbTextCompare) - 1))
        gd = CInt(nomeArquivo)
        ActiveSheet.Range("$A$6:$C$989088").AutoFilter Field:=3, Criteria1:="<>" & gd

The conditions are as follows the name of the file in case it is 1102 and in the filter column it had the following formula =left(c7;4) that returned several values being some of them 1102 so I thought the problem was the formula valorizei and I tried the code above using text, then I tried using numbers and did not get results, what is wrong? Why do not I still filter anything?

    
asked by anonymous 19.09.2017 / 20:52

1 answer

2

Because Excel is interpreting the value in Criteria1 as a number and the values in the C column as text .

Try changing the formula from column C to =VALUE(LEFT(C7, 4)) or if it is Excel in Portuguese VALOR(ESQUERDA(C7; 4)) and then your previous code (without the need of this integer variable):

Dim nomeArquivo As String
nomeArquivo = Left(ThisWorkbook.Name, (InStrRev(ThisWorkbook.Name, ".", -1, vbTextCompare) - 1))
ActiveSheet.Range("$A$6:$C$989088").AutoFilter Field:=3, Criteria1:="<>" & nomeArquivo
    
20.09.2017 / 15:39