PDA

View Full Version : [SOLVED:] How to save multiple selected information from a LISTBOX?



jrsilverio
10-23-2022, 10:16 AM
Save the selected Caption of OptionButton1 and OptionButton2 in column K8?
How to save selected information from a LISTBOX2 in its selection order in cells L8 to U8?
I hope the image sheds some light on the question.

I tried to do what I want based on this tutorial (https://www.automateexcel.com/vba/listbox-selected-item/) but I couldn't, it's too much for my brain

30271

30272




Dim ws As Worksheet
Dim LastRow As Long, x As Long
Set ws = ThisWorkbook.Sheets("Planilha0")
Dim erro As String

erro = ""

'ComboBox2
If Len(ComboBox2) = 0 Then
erro = "Campo de ID inválido" & vbNewLine
End If

'ComboBox3
If Not IsDate(ComboBox3) Then
erro = erro & "Campo de Data inválido" & vbNewLine
End If

'ComboBox4
If Len(ComboBox4) = 0 Then
erro = erro & "Campo da Natureza de Nota Fiscal inválido" & vbNewLine
End If

'ComboBox5
If Len(ComboBox5) = 0 Then
erro = erro & "Campo da Nota Fiscal inválido" & vbNewLine
End If

'ComboBox6
If Len(ComboBox6) = 0 Then
erro = erro & "Campo de Relação de Remessa inválido" & vbNewLine
End If

'ComboBox7
If Len(ComboBox7) = 0 Then
erro = erro & "Campo de Unidade Requisitante inválido!!!"
End If

'ComboBox8
If Len(ComboBox8) = 0 Then
erro = erro & "Campo de Comprador inválido!!!"
End If

'ComboBox8
If Len(ComboBox10) = 0 Then
erro = erro & "Campo de Recebedor inválido!!!"
End If

'ComboBox8
If Len(ComboBox11) = 0 Then
erro = erro & "Campo de Recebimento inválido!!!"
End If

'Error?
If erro <> "" Then
MsgBox erro, vbCritical, "Campo(s) com Erros"
ComboBox4.SetFocus
Exit Sub
End If

With ws
x = 8
Do While .Cells(x, 1) <> ""
x = x + 1
Loop
LastRow = x '.Cells(.Rows.Count, 1).End(xlUp).Row
.Cells(LastRow, 2).Value2 = ComboBox2.Value
.Cells(LastRow, 3).Value2 = CDate(ComboBox3.Value)
.Cells(LastRow, 4).Value2 = ComboBox4.Value
.Cells(LastRow, 5).Value2 = ComboBox5.Value
.Cells(LastRow, 6).Value2 = ComboBox6.Value
.Cells(LastRow, 7).Value2 = ComboBox7.Value
.Cells(LastRow, 8).Value2 = ComboBox8.Value
.Cells(LastRow, 9).Value2 = ComboBox10.Value
.Cells(LastRow, 10).Value2 = ComboBox11.Value
.Cells(LastRow, 22).Value2 = TextBox1.Value
End With

ComboBox4.SetFocus

Call MsgBox("Parabéns!" + vbCrLf + "Cadastro realizado com sucesso." + vbCrLf + vbCrLf + _
"Nº :" & ComboBox1, vbExclamation, "Aviso")

Aussiebear
10-27-2022, 02:30 AM
Your request to delete this thread is declined.