Select in VBA Error 1004

0

Good evening

My spreadsheet has a button where it will open a Form. This Form has a LIST VIEW where the data of a worksheet sheet is loaded. So far so good. Also in Form has a button to filter the LIST VIEW data, based on the values selected in a COMBO BOX. The code below is the filter button, but when it executes, it displays an error in the line ThisWorkbook.Sheets ("FILTER"). Range (Value Range) .Select

Could you tell me why this?

Here is the code for the filter button:

Private Sub btnFiltrar_Click()

    'LIMPA A ABA FILTRO
    ThisWorkbook.Sheets("FILTRO").Cells.Clear

    'COPIA A ABA BASE DE DADOS PARA A ABA FILTRO
    Dim ultima_linha As Long
    ultima_linha = ThisWorkbook.Sheets("BASE_DADOS").Cells(Rows.Count, 1).End(xlUp).Row

    Dim RangeDeValores As String
    RangeDeValores = "A1:G" & CStr(ultima_linha)

    ThisWorkbook.Sheets("BASE_DADOS").Range(RangeDeValores).Copy
    ThisWorkbook.Sheets("FILTRO").Range("A1").PasteSpecial xlAll
    Application.CutCopyMode = False

    'FILTRA NA ABA FILTRO OS ITENS SELECIONADOS NO LIST BOX DE ITENS
    Dim listaItens(99999)

    For i = 0 To fPesquisar.lbItens.ListCount - 1
        If fPesquisar.lbItens.Selected(i) = True Then
            listaItens(i) = fPesquisar.lbItens.List(i)
        End If
    Next i

    ThisWorkbook.Sheets("FILTRO").Range(RangeDeValores).Select

    Selection.AutoFilter
    Selection.AutoFilter Field:=1, Criteria1:=listaItens, Operator:=xlFilterValues


End Sub
    
asked by anonymous 29.06.2017 / 03:41

0 answers