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
Por ecatarucci
Posts
#16038
Galera, boa tarde!

O alexandrevba me ajudou a criar um VBA em que eu pesquise o valor em uma combo box e retorne o valor em uma text box correspondente da linha pesquisada. Eu preciso inverter agora. O VBA abaixo pesquisa descrição e retorna código. Preciso que pesquise código e retorne a descrição:

“Private Sub cbxDescr_Change()
'Verifica qual descrição corresponde a determinado Código, mostra na Textbox
Dim res As Variant
On Error Resume Next
res = Application.Index(Range("'Guia_BD'!$A$2:$B$12"), Application.Match(cbxDescr.Value, Range("'Guia_BD'!$B$2:$B$12"), 0), 1)
txtCod.Value = res
End Sub

Private Sub UserForm_Initialize()
'Após iniciar o UserForm, carrega os dados de uma guia em um combobox que estão na guia Guia_BD
With Worksheets("Guia_BD")
Me.cbxDescr.List = .Range(.Cells(2, 2), .Cells(.Rows.Count, 2).End(xlUp)).Value
End With
End Sub


Os códigos estão na coluna A e a descrição na coluna B.

Tentei inverter todos os códigos que estão ai e não consegui nada :|

E se puder me explicar o que foi necessário fazer, pq eu consegui pesquisar o código mas a descrição não aparecia.

Sei que é uma coisa simples, mas pra quem não tem o domínio da ferramenta, ai complica rs

Desde já, obrigado.
Avatar do usuário
Por alexandrevba
Avatar
#16040
Boa tarde!!

Caso for substituir o Textbox pelo combobox, tente o PROCV
Código: Selecionar todos
    If Len(txtCod.Text) >= 1 Then
        form1 = WorksheetFunction.VLookup(Val(txtCod.Text), Worksheets("Guia_BD").Range("A1:B100000"), 2, 0)
        If Err.Number = 0 Then
            txtDescr.Text = form1
        End If
    End If

Att
Avatar do usuário
Por alexandrevba
Avatar
#16093
Bom dia!!

Veja o anexo.


Att
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