Boa tarde, o seguinte código abaixo, está salvando os dados digitados, porém quando clico em cadastrar para gerar um novo, ele apaga os dados dos mesmos, preciso que fique salvo todos os cadastros que fizer:
Private Sub CommandButton9_Click()
' Declarar variáveis
Dim ws As Worksheet
Dim LastRow As Long
Dim ID As String
Dim Nome As String
Dim Endereco As String
Dim Cidade As String
Dim Telefone As String
Dim Item(1 To 6) As String
Dim Corte(1 To 6) As String
Dim Quantidade(1 To 6) As String
Dim Descricao(1 To 6) As String
Dim PrecoUnitario(1 To 6) As String
Dim PrecoTotal(1 To 6) As String
Dim i As Integer
' Configurar a planilha
Set ws = ThisWorkbook.Sheets("Pedidos")
' Encontrar a última linha disponível
LastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row + 1
' Verificar se o campo Nome está vazio
If txt_Nome.Text = "" Then
MsgBox "Preencha os Campos"
txt_Nome.SetFocus
Exit Sub
End If
' Atribuir valores às variáveis
ID = txt_Pedido.Text
Nome = txt_Nome.Text
Endereco = txt_Endereço.Text
Cidade = txt_Cidade.Text
Telefone = txt_Telefone.Text
For i = 1 To 6
Item(i) = Me.Controls("Item_" & i).Text
Corte(i) = Me.Controls("Corte_" & i).Text
Quantidade(i) = Me.Controls("Quantidade_" & i).Text
Descricao(i) = Me.Controls("Descrição_" & i).Text
PrecoUnitario(i) = Me.Controls("PU_" & i).Text
PrecoTotal(i) = Me.Controls("PT_" & i).Text
Next i
' Preencher a planilha com os valores
With ws
.Cells(LastRow, 1).Value = ID
.Cells(LastRow, 2).Value = Nome
.Cells(LastRow, 3).Value = Endereco
.Cells(LastRow, 4).Value = Cidade
.Cells(LastRow, 5).Value = Telefone
For i = 1 To 6
.Cells(LastRow, 5 + (i - 1) * 6 + 1).Value = Item(i)
.Cells(LastRow, 5 + (i - 1) * 6 + 2).Value = Corte(i)
.Cells(LastRow, 5 + (i - 1) * 6 + 3).Value = Quantidade(i)
.Cells(LastRow, 5 + (i - 1) * 6 + 4).Value = Descricao(i)
.Cells(LastRow, 5 + (i - 1) * 6 + 5).Value = PrecoUnitario(i)
.Cells(LastRow, 5 + (i - 1) * 6 + 6).Value = PrecoTotal(i)
Next i
End With
' Limpar os campos do formulário
txt_Nome.Text = ""
txt_Endereço.Text = ""
txt_Cidade.Text = ""
txt_Telefone.Text = ""
For i = 1 To 6
Me.Controls("Item_" & i).Text = ""
Me.Controls("Corte_" & i).Text = ""
Me.Controls("Quantidade_" & i).Text = ""
Me.Controls("Descrição_" & i).Text = ""
Me.Controls("PU_" & i).Text = ""
Me.Controls("PT_" & i).Text = ""
Next i
End Sub