Página 1 de 1

Gerar ListBox a partir de seleção anterior de optionbox e combobox

Enviado: 21 Jun 2021 às 19:06
por coutinhoicaro
boa noite a todos, sou novato em uso de VBA, estou tentando automatizar uns dados que utilizo, A dinamica é a seguinte:
Eu seleciono 1 das (3) optionbox do meu codigo, e após isso seleciono um dos itens da combobox(que sempre são os mesmo itens)

ao primeiro selecionar uma das optionbox ela me da um valor diferente ao selecionar o item da combobox depois.



Ex:

optionbox(NORMAL) --> combobox(ppm) --> textbox(1,5)

optionbox(EXCEPCIONAL) --> combobox(ppm) --> textbox(1,1)



dito isso quero que seja gerada uma lista com o resultado que sai na textbox (1,5)

desculpe o codigo feio estou aprendendo então tem umas gambiarras que deram certo rs

A tabela está desta maneira.

1 PPM 1,25 1,15 1,1
2 PPP 1,3 1,2 1,15
3 PPL 1,35 1,25 1,15
4 PPEI 1,4 1,3 1,2
5 PPEQ 1,5 1,4 1,3
6 INDI 1,2 1,2 0

obrigado desde já

Att.

Segue o codigo.

Private Sub btDeletar_Click()
Dim nlin As Integer

If tgbEditar.Value = True Then
nlin = ListBox1.ListIndex
If nlin = -1 Then
MsgBox "Selecione um item para deletar"
Exit Sub
ElseIf ListBox1.Value = 0 Then
MsgBox "Selecione um item para deletar"
Exit Sub
End If
Call Deletar
Else
MsgBox "Coloque no modo edição!"
End If


End Sub

Private Sub btOk_Click()

Dim nlin As Integer

If tgbEditar.Value = True Then
nlin = ListBox1.ListIndex
If nlin = -1 Then
MsgBox "Selecione um item para editar"
Exit Sub
ElseIf ListBox1.Value = 0 Then
MsgBox "Selecione um item para editar"
Exit Sub
End If
Call Editar
Else
Call Inserir
End If

End Sub


Private Sub cbbComboBox1_Change()

If OptionButton1 = True And cbbComboBox1.Value = "PPM" Then
TextBox1.Value = Range("Plan2!c2")
End If

If OptionButton1 = True And cbbComboBox1.Value = "PPP" Then
TextBox1.Value = Range("Plan2!c3")
End If

If OptionButton1 = True And cbbComboBox1.Value = "PPL" Then
TextBox1.Value = Range("Plan2!c4")
End If

If OptionButton1 = True And cbbComboBox1.Value = "PPEI" Then
TextBox1.Value = Range("Plan2!c5")
End If

If OptionButton1 = True And cbbComboBox1.Value = "PPEQ" Then
TextBox1.Value = Range("Plan2!c6")
End If

If OptionButton1 = True And cbbComboBox1.Value = "INDI" Then
TextBox1.Value = Range("Plan2!c7")
End If

If OptionButton2 = True And cbbComboBox1.Value = "PPM" Then
TextBox1.Value = Range("Plan2!d2")
End If

If OptionButton2 = True And cbbComboBox1.Value = "PPP" Then
TextBox1.Value = Range("Plan2!d3")
End If

If OptionButton2 = True And cbbComboBox1.Value = "PPL" Then
TextBox1.Value = Range("Plan2!d4")
End If

If OptionButton2 = True And cbbComboBox1.Value = "PPEI" Then
TextBox1.Value = Range("Plan2!d5")
End If

If OptionButton2 = True And cbbComboBox1.Value = "PPEQ" Then
TextBox1.Value = Range("Plan2!d6")
End If

If OptionButton2 = True And cbbComboBox1.Value = "INDI" Then
TextBox1.Value = Range("Plan2!d7")
End If

If OptionButton2 = True And cbbComboBox1.Value = "PPM" Then
TextBox1.Value = Range("Plan2!e2")
End If

If OptionButton3 = True And cbbComboBox1.Value = "PPP" Then
TextBox1.Value = Range("Plan2!e3")
End If

If OptionButton3 = True And cbbComboBox1.Value = "PPL" Then
TextBox1.Value = Range("Plan2!e4")
End If

If OptionButton3 = True And cbbComboBox1.Value = "PPEI" Then
TextBox1.Value = Range("Plan2!e5")
End If

If OptionButton3 = True And cbbComboBox1.Value = "PPEQ" Then
TextBox1.Value = Range("Plan2!e6")
End If

If OptionButton3 = True And cbbComboBox1.Value = "INDI" Then
TextBox1.Value = Range("Plan2!e7")
End If

End Sub

Private Sub cbbComboBox2_Change()
If OptionButton1 = True And cbbComboBox2.Value = "PPM" Then
TextBox2.Value = Range("Plan2!c2")
End If

If OptionButton1 = True And cbbComboBox2.Value = "PPP" Then
TextBox2.Value = Range("Plan2!c3")
End If

If OptionButton1 = True And cbbComboBox2.Value = "PPL" Then
TextBox2.Value = Range("Plan2!c4")
End If

If OptionButton1 = True And cbbComboBox2.Value = "PPEI" Then
TextBox2.Value = Range("Plan2!c5")
End If

If OptionButton1 = True And cbbComboBox2.Value = "PPEQ" Then
TextBox2.Value = Range("Plan2!c6")
End If

If OptionButton1 = True And cbbComboBox2.Value = "INDI" Then
TextBox2.Value = Range("Plan2!c7")
End If

If OptionButton2 = True And cbbComboBox2.Value = "PPM" Then
TextBox2.Value = Range("Plan2!d2")
End If

If OptionButton2 = True And cbbComboBox2.Value = "PPP" Then
TextBox2.Value = Range("Plan2!d3")
End If

If OptionButton2 = True And cbbComboBox2.Value = "PPL" Then
TextBox2.Value = Range("Plan2!d4")
End If

If OptionButton2 = True And cbbComboBox2.Value = "PPEI" Then
TextBox2.Value = Range("Plan2!d5")
End If

If OptionButton2 = True And cbbComboBox2.Value = "PPEQ" Then
TextBox2.Value = Range("Plan2!d6")
End If

If OptionButton2 = True And cbbComboBox2.Value = "INDI" Then
TextBox2.Value = Range("Plan2!d7")
End If

If OptionButton2 = True And cbbComboBox2.Value = "PPM" Then
TextBox2.Value = Range("Plan2!e2")
End If

If OptionButton3 = True And cbbComboBox2.Value = "PPP" Then
TextBox2.Value = Range("Plan2!e3")
End If

If OptionButton3 = True And cbbComboBox2.Value = "PPL" Then
TextBox2.Value = Range("Plan2!e4")
End If

If OptionButton3 = True And cbbComboBox2.Value = "PPEI" Then
TextBox2.Value = Range("Plan2!e5")
End If

If OptionButton3 = True And cbbComboBox2.Value = "PPEQ" Then
TextBox2.Value = Range("Plan2!e6")
End If

If OptionButton3 = True And cbbComboBox2.Value = "INDI" Then
TextBox2.Value = Range("Plan2!e7")
End If

End Sub

Private Sub cbbComboBox3_Change()
If cbbComboBox3.Value = "1" Then
TextBox3.Value = Range("Plan2!b2")

ElseIf cbbComboBox3.Value = "2" Then
TextBox3.Value = Range("Plan2!b3")

ElseIf cbbComboBox3.Value = "3" Then
TextBox3.Value = Range("Plan2!b4")

ElseIf cbbComboBox3.Value = "4" Then
TextBox3.Value = Range("Plan2!b5")

ElseIf cbbComboBox3.Value = "5" Then
TextBox3.Value = Range("Plan2!b6")

ElseIf cbbComboBox3.Value = "6" Then
TextBox3.Value = Range("Plan2!b7")

ElseIf cbbComboBox3.Value = "7" Then
TextBox3.Value = Range("Plan2!b8")

ElseIf cbbComboBox3.Value = "8" Then
TextBox3.Value = Range("Plan2!b9")

ElseIf cbbComboBox3.Value = "9" Then
TextBox3.Value = Range("Plan2!b10")

End If
End Sub

Private Sub Frame1_Click()

End Sub

Private Sub ListBox1_Change()
Dim nlin As Integer
nlin = ListBox1.ListIndex
If nlin = -1 Then Exit Sub

If bloqueado = True Then Exit Sub
If ListBox1.Value = 0 Then
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
Else
TextBox1.Value = ListBox1.List(nlin, 1)
TextBox2.Value = ListBox1.List(nlin, 2)
TextBox3.Value = ListBox1.List(nlin, 3)
End If


End Sub


Private Sub TextBox1_Change()

End Sub

Private Sub UserForm_Initialize()

cbbComboBox1.AddItem "PPM"
cbbComboBox1.AddItem "PPP"
cbbComboBox1.AddItem "PPL"
cbbComboBox1.AddItem "PPEI"
cbbComboBox1.AddItem "PPEQ"
cbbComboBox1.AddItem "INDI"


cbbComboBox2.AddItem "PPM"
cbbComboBox2.AddItem "PPP"
cbbComboBox2.AddItem "PPL"
cbbComboBox2.AddItem "PPEI"
cbbComboBox2.AddItem "PPEQ"
cbbComboBox2.AddItem "INDI"

cbbComboBox3.AddItem "1"
cbbComboBox3.AddItem "2"
cbbComboBox3.AddItem "3"
cbbComboBox3.AddItem "4"
cbbComboBox3.AddItem "5"
cbbComboBox3.AddItem "6"
cbbComboBox3.AddItem "7"
cbbComboBox3.AddItem "8"
cbbComboBox3.AddItem "9"

Call Atualizar_ListBox

End Sub

image.png

Re: Gerar ListBox a partir de seleção anterior de optionbox e combobox

Enviado: 12 Jul 2021 às 23:13
por Strogonoff
Caro coutinho,
aqui está mais fácil...
recomendo :
1) colocar os valores do combobox numa planilha e depois selecioná-los de lá , assim se precisar alterar, já estão numa planilha auxiliar;
2) crie uma variável para receber os option box ( pode ser uma integer), quando a pessoa clica nessa variável, você já tem um valor selecionado.
3) de uma olhada na instrução select case, pois vocÊ armazenando o valor da optionbox numa variavel, você poderá " jogar instruções conforme resultado
espero aqui ter ajudado em algo
Abraço