Hi everyone!
I have had such a headache with this. I have a very long VBA code that works with around 7 workbooks, it goes perfectly well, until I try to filter one of the sheets using a command I use constantly:
Function CriarArquivos(operation As String, Concessionaria As String, PlanilhaBase As String) As Boolean
Dim countLines As Long
Dim countFiltro As Integer
'Activate the correct Workbook and Sheet
Workbooks(PlanilhaBase).Sheets(1).Activate
'countLines gets the total number of rows with data in the file
countLines = Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count
Range("A1:J1").Select
' Filter by Concessionaria
ActiveSheet.Range("$A$1:$J" & countLines).AutoFilter Field:=5, Criteria1:="" & Concessionaria
' Defines countFiltro as the total number of rows for the filtered list
countFiltro = ActiveSheet.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count
' Start the code if at least one item was found.
If countFiltro > 1 Then
The variables:
countFiltro which should return the number of rows filtered by the Autofilter but it is returning always 1
The Activesheet, after the Macro has run, does not seem to be filtered at all
Funny thing is that it works perfectly if I go into debug mode and keep F8 pressed.
I am trying to debug this using Debug.Print. The conditional statement gets always FALSE in this way.
I have turned internet upside down to find solutions, I have already tried to:
Add DoEvents in case it was a processing issue,
Tried to copy the whole code and data to another file in case the original one was corrupt.
Removed all the WITH statements from the whole code, since it has been an issue found online...
Restarted Excel
Restarted the Computer
Nothing works...
Any thoughts ?
Bookmarks