Autofilter Excel VBA

Asked

Viewed 815 times

0

I have a problem, when trying to make an autofilter in vba it is trying to filter the values I chose but ends up not filtering 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 the following the file name in case is 1102 and in the filter column had the following formula =left(c7;4) that returned several values being some of them 1102 so I thought the problem was the formula valorized and tried the above code using text, then tried using numbers and got no result, what is wrong ? why I keep not filtering anything?

1 answer

3


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

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

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
  • Thanks for the help but is still giving in the same... I do not know what else to do with this file... Continue filtering anything

  • Can provide an example for download?

  • Dude, I was making one to send to you and I noticed that it’s filtering the value, but it’s not on my filter list... so it’s working just not showing up on my list. Fighting for help...

  • You mean when you open the list it doesn’t appear marked? I don’t understand. Anyway, I’m glad you solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.