Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
#71381
Fala galera!

O código abaixo é executado em formulário que criei; bem, o objetivo dele é realizar filtros na tabela a partir do preenchimento de seus campos e então pegar o sub-intervalo, após aplicação do filtro na tabela e na sequência carregar no listview.

Antes de realizar qualquer filtro a variável htx = ShtNFe.Range("A1").CurrentRegion.Rows.Count tem valor 9 que é a altura da minha tabela sem filtros aplicados, após aplicar filtros esse valor continua o mesmo, independente de rodar a variável antes ou depois do filtro. Tô quebrando a cabeça aqui… ainda não consegui obter resultado diferente, se alguém puder ajudar🤙🏽

Imagem

"Sei que consigo fazer de outras formas, mas no poste atual queria mais um reflexão do porquê não funciona como esperado, pois CurrentRegion deveria me fornecer os o intervalo atual e as propriedades .Rows.Count a altura do intervalo atual (Entender isso é uma condição pra mim, pois não vejo impedimento para que funcione.)"
Código: Selecionar todos
Sub Filtro_Criterio()

'REPRESENTA A ALTURA 'x' DO INTERVALO ATUAL
Dim htx             As Long

'VARIAVEIS QUE RECEBEM OS VALORES DOS 'txtbox'
Dim txtCNPJ, txtFornecedor, txtNota, txtChave, txtCodFisc, txtProduto, cbDest, cbAnex  As String
Dim txtcod, txtncm As String

'ARRAY QUE DEVE SER CARREGADO COM DADOS DA REGIAO ATUAL APOS EXECUCAO DO FILTRO
Dim arrCurrent      As Variant
'LOOP
Dim i               As Long
'MATRIZ UTILIZADA P/ RECEBER DADOS DE 'arrCurrent' P/ CARREGAR NO LISTBOX
Dim arrMatrix()     As Variant

On Error Resume Next

With Frm_Ajuste
    txtCNPJ = "*" & .txt_cnpj.Text & "*"
    txtFornecedor = "*" & .txt_fornecedor.Text & "*"
    txtNota = "*" & .txt_nota.Text & "*"
    txtChave = "*" & .txt_chave.Text & "*"
    txtCodFisc = "*" & .txt_cfop.Text & "*"
    txtProduto = "*" & .txt_produto.Text & "*"
    cbDest = "*" & .cb_dest_pesq.Text & "*"
    cbAnex = "*" & .cb_anexo_pesq.Text & "*"
    txtcod = "*" & .txt_cod.Text & "*"
    txtncm = "*" & .txt_ncm.Text & "*"
End With


ShtNFe.Activate
htx = ShtNFe.Range("A1").CurrentRegion.Rows.Count

With ShtNFe.Range("A1")
    .AutoFilter Field:=7, Criteria1:=txtCNPJ, visibleDropDown:=False
    .AutoFilter Field:=8, Criteria1:=txtFornecedor, visibleDropDown:=False
    .AutoFilter Field:=5, Criteria1:=txtNota, visibleDropDown:=False
    .AutoFilter Field:=1, Criteria1:=txtChave, visibleDropDown:=False
    .AutoFilter Field:=18, Criteria1:=txtCodFisc, visibleDropDown:=False
    .AutoFilter Field:=15, Criteria1:=txtProduto, visibleDropDown:=False
    .AutoFilter Field:=52, Criteria1:=cbDest, visibleDropDown:=False
    .AutoFilter Field:=51, Criteria1:=cbAnex, visibleDropDown:=False
    .AutoFilter Field:=14, Criteria1:=txtcod, visibleDropDown:=False
    .AutoFilter Field:=16, Criteria1:=txtncm, visibleDropDown:=False
End With
    
    
    arrCurrent = ShtNFe.Range("A1").CurrentRegion.Offset(1).Resize(htx - 1)
    
    ReDim arrMatrix(1 To htx, 1 To 9) As Variant
    
    For i = 1 To UBound(arrCurrent)
        arrMatrix(htx, 1) = arrCurrent(i, 5)
        arrMatrix(htx, 2) = arrCurrent(i, 14)
        arrMatrix(htx, 3) = arrCurrent(i, 15)
        arrMatrix(htx, 4) = arrCurrent(i, 16)
        arrMatrix(htx, 5) = arrCurrent(i, 47)
        arrMatrix(htx, 6) = arrCurrent(i, 48)
        arrMatrix(htx, 7) = arrCurrent(i, 49)
        arrMatrix(htx, 8) = arrCurrent(i, 50)
        arrMatrix(htx, 9) = arrCurrent(i, 52)
        htx = htx - 1
    Next i

Frm_Ajuste.ListBox2.ColumnWidths = "53;77;255;55;38;38;38;40;10"
Frm_Ajuste.ListBox2.List = arrMatrix

End Sub
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord