I need to move this search to a userform that currently performs a search on sheet 1 I would like to put the database on sheet 2, everything works but the insert function cannot find the last row.
Private Sub ComboBox1_Change()
Dim Riga As Long
If ComboBox1.Value <> "" Then
Riga = ComboBox1.ListIndex + 2
Cells(Riga, 1).Select
TextBox1 = ComboBox1.Value
TextBox2 = Sheets(2).Cells(ActiveCell.Row, 2)
TextBox3 = Sheets(2).Cells(ActiveCell.Row, 3)
TextBox4 = Sheets(2).Cells(ActiveCell.Row, 4)
TextBox5 = Sheets(2).Cells(ActiveCell.Row, 5)
TextBox6 = Sheets(2).Cells(ActiveCell.Row, 6)
End If
End Sub
Private Sub CommandButton_Chiudi_Click()
Unload Me
End Sub
Private Sub CommandButton_Nuovo_Click()
Dim tx As Byte
ComboBox1.Value = ""
Cells(Range("A1").End(xlDown).Row + 1, 1).Select
For tx = 1 To 6
Userform1.Controls("TextBox" & tx).Text = ""
Next tx
TextBox1.SetFocus
End Sub
Private Sub CommandButton_Cancella_Click()
Dim Messaggio As String, Stile As String, Titolo As String
Dim Risposta As VbMsgBoxResult
Titolo = "Cancellazione Record."
Messaggio = "Vuoi cancellare il tesserino:" & Chr(10) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 1) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 2) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 3) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 4) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 5) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 6) & Chr(10)
Stile = vbYesNo + vbQuestion + vbDefaultButton2
Risposta = MsgBox(Messaggio, Stile, Titolo)
If Risposta = vbNo Then End
ActiveCell.EntireRow.Delete
End
End Sub
Private Sub CommandButton_Aggiorna_Click()
Dim Riga As Long
Dim Messaggio As String, Stile As String, Titolo As String
Dim Risposta As VbMsgBoxResult
Titolo = "Cancellazione Record."
Messaggio = "Vuoi registrare il tesserino:" & Chr(10) & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 1).Value & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 2).Value & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 3).Value & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 4).Value & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 5).Value & Chr(10) _
& Sheets(2).Cells(ActiveCell.Row, 6).Value & Chr(10) & Chr(10) _
& "con:" & Chr(10) _
& TextBox1.Value & Chr(10) _
& TextBox2.Value & Chr(10) _
& TextBox3.Value & Chr(10) _
& TextBox4.Value & Chr(10) _
& TextBox5.Value & Chr(10) _
& TextBox6.Value
Stile = vbYesNo + vbQuestion + vbDefaultButton2
Risposta = MsgBox(Messaggio, Stile, Titolo)
If Risposta = vbNo Then End
Riga = ActiveCell.Row
ComboBox1.Value = ""
Sheets(2).Cells(Riga, 1) = TextBox1.Value
Sheets(2).Cells(Riga, 2) = TextBox2.Value
Sheets(2).Cells(Riga, 3) = TextBox3.Value
Sheets(2).Cells(Riga, 4) = TextBox4.Value
Sheets(2).Cells(Riga, 5) = TextBox5.Value
Sheets(2).Cells(Riga, 6) = TextBox6.Value
ComboBox1.SetFocus
End Sub
how can I do to indicate that with the insert new record function I find the last row on the database that I have moved to sheet 2? thank you
sheets(2).Cells(Range("A1").End(xlDown).Row + 1, 1).Select
it doesn't work and I go into error