Hello! I've been trying to deal with this for hours and I just can't seem to find where the problem is.
First of all, the script checks if a cell range is empty or not. If it is empty, then it does something. If it is not empty, then it does another thing. The problem I have is that even though the range is empty, it must run twice for the "empty" action to work. The "not empty" always works as it should. What am I doing wrong here?
Thanks in advance!
First of all, the script checks if a cell range is empty or not. If it is empty, then it does something. If it is not empty, then it does another thing. The problem I have is that even though the range is empty, it must run twice for the "empty" action to work. The "not empty" always works as it should. What am I doing wrong here?
Thanks in advance!
Code:
Sub FilterIt2()
If WorksheetFunction.CountA(Sheets("Pesquisar").Range("B6:G6")) = 0 Then
'se estiver vazia
Sheets("Pesquisar").Range("A10:H1000").Clear
Sheets("Base de Dados").Select
Range("A1:G1000").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Pesquisar").Select
Range("B10").Select
ActiveSheet.Paste
Call NewTable
Else
'se não estiver vazia
Sheets("Pesquisar").Range("A10:H1000").Clear
Sheets("Base de Dados").Range("A1").CurrentRegion.AdvancedFilter _
Action:=xlFilterInPlace, _
CriteriaRange:=Sheets("Pesquisar").Range("B5:G6"), _
Unique:=False
Set Rng = Sheets("Base de Dados").Range("A1").CurrentRegion.SpecialCells(xlVisible)
With Sheets("Base de Dados") 'exibir todo o conteúdo da base de dados
If .FilterMode Then
.ShowAllData
End If
End With
Rng.Copy
Sheets("Pesquisar").Range("B10:H10").PasteSpecial Paste:=xlPasteAll 'definição de onde colar o conteúdo da Base de Dados
Application.CutCopyMode = False
Call NewTable
End If
End Sub