PDA

View Full Version : [SOLVED:] Help for viable registration solution and code improvement



jrsilverio
10-15-2022, 05:06 AM
Make the "Não" option in the checkbox already marked, and if one of the two is chosen, send it to the spreadsheet in cell K8 if the user chose "Sim or Não".


If he chooses Sim, saves the information, and allows him to make the change below.


Help to make a viable way in which the USER can select more than one item in ListBox2, and that each selected item is saved in the order of selection in the worksheet, that is, in the columns "Inter1, Inter2, Inter3... until Inter9 ) as selected.



Dim ws As Worksheet
Dim LastRow As Long, x As Long
Set ws = ThisWorkbook.Sheets("Planilha0")
Dim erro As String
'Valor inicial antes de iniciar a gravação
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
'Verifica se houve algum erro
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")


30239


Plan

30240

jrsilverio
10-16-2022, 04:54 AM
Updated worksheet, still with the problem