My question is this: I have developed a 20-field VBA form, which registers in the BDados worksheet, also inserting an ID. What I want is to find and Copy a record from the worksheet to the form, filling in all its fields after changing some of them and writing to the BData with new ID.
In Excel it will be the same as copying a row, pasting a new row, and changing the ID and some cells.
It remains to be added that the ID is automatically inserted when the form is opened.
I'm a layman in VBA Excel and I still can not find an example that will inspire me for my project.
Thank you. For help.
THE CODE ALREADY DEVELOPED IS THE FOLLOWING:
Private Sub BTN_GRAVAR_Click()
Dim NR As Long
Dim DATA_MATRICULA As Date
Dim DATA_INICIAL As Date
Dim DATA_FINAL As Date
Folha2.Select
Range("A3").End(xlDown).Select
NR = ActiveCell.Row
Range("a65536").End(xlUp).Offset(1, 0).Select
ActiveCell.Offset(0, 0).Value = LBL_NR.Caption
ActiveCell.Offset(0, 1).Value = txtident.Text
ActiveCell.Offset(0, 2).Value = txtmatricula.Text
ActiveCell.Offset(0, 3).Value = txtdata.Text
ActiveCell.Offset(0, 4).Value = txtcilindrada.Text
ActiveCell.Offset(0, 5).Value = txtpeso.Text
ActiveCell.Offset(0, 6).Value = Cbocombustivel.Text
ActiveCell.Offset(0, 7).Value = cbolugares.Text
ActiveCell.Offset(0, 8).Value = cbotipo.Text
ActiveCell.Offset(0, 9).Value = cbocategoria.Text
ActiveCell.Offset(0, 10).Value = txtpneuf.Text
ActiveCell.Offset(0, 11).Value = txtpneut.Text
ActiveCell.Offset(0, 12).Value = cboseguradora.Text
ActiveCell.Offset(0, 13).Value = txtapolice.Text
ActiveCell.Offset(0, 14).Value = txtvalorizacao.Text
ActiveCell.Offset(0, 15).Value = txtinicial.Text
ActiveCell.Offset(0, 16).Value = txtfinal.Text
ActiveCell.Offset(0, 17).Value = Txtvalor.Text
ActiveCell.Offset(0, 18).Value = txttaxa.Text
ActiveCell.Offset(0, 19).Value = cbocentro.Text
Columns("A:T").AutoFit
txtident.Text = ""
txtmatricula.Text = ""
txtdata.Text = ""
txtcilindrada.Text = ""
txtpeso.Text = ""
Cbocombustivel.Value = ""
cbolugares.Value = ""
cbotipo.Value = ""
cbocategoria.Value = ""
txtpneuf.Text = ""
txtpneut.Text = ""
cboseguradora.Value = ""
txtapolice.Text = ""
txtvalorizacao.Text = ""
txtinicial.Text = ""
txtfinal.Text = ""
Txtvalor.Text = ""
txttaxa.Text = ""
cbocentro.Value = ""
Me.LBL_NR = Folha2.Range("a65536").End(xlUp).Row - 1
txtident.SetFocus
End Sub
Private Sub BTN_Sair_Click()
Unload Me
End Sub
Private Sub txtdata_Change()
If Len(Me.txtdata.Text) = 2 Then
Me.txtdata.Text = Me.txtdata.Text & "/"
Me.txtdata.SelStart = 4
ElseIf Len(Me.txtdata.Text) = 5 Then
Me.txtdata.Text = Me.txtdata.Text & "/"
Me.txtdata.SelStart = 7
ElseIf Len(Me.txtdata.Text) = 10 Then
Me.txtcilindrada.SetFocus
End If
End Sub
Private Sub txtinicial_Change()
If Len(Me.txtinicial.Text) = 2 Then
Me.txtinicial.Text = Me.txtinicial.Text & "/"
Me.txtinicial.SelStart = 4
ElseIf Len(Me.txtinicial.Text) = 5 Then
Me.txtinicial.Text = Me.txtinicial.Text & "/"
Me.txtinicial.SelStart = 7
ElseIf Len(Me.txtinicial.Text) = 10 Then
Me.txtfinal.SetFocus
End If
End Sub
Private Sub txtfinal_Change()
If Len(Me.txtfinal.Text) = 2 Then
Me.txtfinal.Text = Me.txtfinal.Text & "/"
Me.txtfinal.SelStart = 4
ElseIf Len(Me.txtfinal.Text) = 5 Then
Me.txtfinal.Text = Me.txtfinal.Text & "/"
Me.txtfinal.SelStart = 7
ElseIf Len(Me.txtfinal.Text) = 10 Then
Me.Txtvalor.SetFocus
End If
End Sub
Private Sub txtmatricula_Change()
If Len(Me.txtmatricula.Text) = 2 Then
Me.txtmatricula.Text = Me.txtmatricula.Text & "-"
Me.txtmatricula.SelStart = 4
ElseIf Len(Me.txtmatricula.Text) = 5 Then
Me.txtmatricula.Text = Me.txtmatricula.Text & "-"
Me.txtmatricula.SelStart = 8
ElseIf Len(Me.txtmatricula.Text) = 8 Then
Me.txtdata.SetFocus
End If
End Sub
Private Sub UserForm_Initialize()
Me.LBL_NR = Folha2.Range("a65536").End(xlUp).Row
End Sub