Trying to emulate what the form command does from the quick access toolbar.
I don't know if it is possible to put this form command on a worksheet with a button, couldn't find anything about this and I suppose it is a Excel functionality which you can't generate on a worksheet.
So I found the next best thing which is making a userform to search and add data, only it only searchs for 1 criteria and I want to search for 2 criteria, email and last name.
The problem is that it doesn't work even for 1 criteria, it is probably that I have an automated insert for an ID number in Column A (this is done with another userform)
The input on my worksheet starts A5, so I tried to change the i =2 to i = 5 and some other fiddling, but to no avail. My knowledge of VBA is very poor, so I was hoping for someone to help solving this problem.
The code below is changed because the original code started from the first textbox and not the second textbox on the userform
.
I don't know if it is possible to put this form command on a worksheet with a button, couldn't find anything about this and I suppose it is a Excel functionality which you can't generate on a worksheet.
So I found the next best thing which is making a userform to search and add data, only it only searchs for 1 criteria and I want to search for 2 criteria, email and last name.
The problem is that it doesn't work even for 1 criteria, it is probably that I have an automated insert for an ID number in Column A (this is done with another userform)
The input on my worksheet starts A5, so I tried to change the i =2 to i = 5 and some other fiddling, but to no avail. My knowledge of VBA is very poor, so I was hoping for someone to help solving this problem.
The code below is changed because the original code started from the first textbox and not the second textbox on the userform
.
VBA Code:
Private Sub cmdbtnSearch_Click()
Dim LastName As String
LastName = Trim(tbLast_name.Text)
LastRow = Worksheets("Guests").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To LastRow
If Worksheets("Guests").Cells(i, 2).Value = LastName Then
tbFirst_name.Text = Worksheets("Guests").Cells(i, 1).Value
tbDob.Text = Worksheets("Guests").Cells(i, 3).Value
tbNationality.Text = Worksheets("Guests").Cells(i, 4).Value
tbPassport.Text = Worksheets("Guests").Cells(i, 5).Value
optMale.Text = Worksheets("Guests").Cells(i, 6).Value
tbEmail.Text = Worksheets("Guests").Cells(i, 7).Value
tbPhone.Text = Worksheets("Guests").Cells(i, 8).Value
tbEmergency.Text = Worksheets("Guests").Cells(i, 9).Value
tbAllergies.Text = Worksheets("Guests").Cells(i, 10).Value
tbRemarks.Text = Worksheets("Guests").Cells(i, 11).Value
tbBook.Text = Worksheets("Guests").Cells(i, 12).Value
End If
Next