Hello,
I have spent almost a week trying to get my userform to work. My eyes are really bad, and a user form will help immensely.
The buttons enter, search, and exit work for me; however,Edit and Delete do not. I'd like to change my exit button to exit and save. The sheet's headers are ID, First Name, Last Name, Phone 1, Phone 2, Email, Address, City, State, Zip, and Notes.
Please can anyone assist me? Here is the code which I found here and there from other spreadsheet examples:
Command Button 1 is Enter, Command Button 2 is Search, Command Button 3 is Edit, Command Button 4 is delete, Command Button 5 is Exit
Code
- Private Sub CommandButton1_Click()
- Dim LastRow As Object
- Set LastRow = Sheet1.Range("a65536").End(xlUp)
- LastRow.Offset(1, 0).Value = TextBox1.Text
- LastRow.Offset(1, 1).Value = TextBox2.Text
- LastRow.Offset(1, 2).Value = TextBox3.Text
- LastRow.Offset(1, 3).Value = TextBox4.Text
- LastRow.Offset(1, 4).Value = TextBox5.Text
- LastRow.Offset(1, 5).Value = TextBox6.Text
- LastRow.Offset(1, 6).Value = TextBox7.Text
- LastRow.Offset(1, 7).Value = TextBox8.Text
- LastRow.Offset(1, 8).Value = TextBox9.Text
- LastRow.Offset(1, 9).Value = TextBox10.Text
- LastRow.Offset(1, 10).Value = TextBox11.Text
- MsgBox "One record written to Sheet1"
- response = MsgBox("Do you want to enter another record?", _
- vbYesNo)
- If response = vbYes Then
- TextBox1.Text = ""
- TextBox2.Text = ""
- TextBox3.Text = ""
- TextBox4.Text = ""
- TextBox5.Text = ""
- TextBox6.Text = ""
- TextBox7.Text = ""
- TextBox8.Text = ""
- TextBox9.Text = ""
- TextBox10.Text = ""
- TextBox11.Text = ""
- TextBox1.SetFocus
- Else
- Unload Me
- End If
- End Sub
- Private Sub CommandButton2_Click()
- Do
- DoEvents
- row_number = row_number + 1
- item_in_review = Sheet1.Range("A" & row_number)
- If item_in_review = TextBox1.Text Then
- TextBox2.Text = Sheet1.Range("B" & row_number)
- TextBox3.Text = Sheet1.Range("C" & row_number)
- TextBox4.Text = Sheet1.Range("D" & row_number)
- TextBox5.Text = Sheet1.Range("E" & row_number)
- TextBox6.Text = Sheet1.Range("F" & row_number)
- TextBox7.Text = Sheet1.Range("G" & row_number)
- TextBox8.Text = Sheet1.Range("H" & row_number)
- TextBox9.Text = Sheet1.Range("I" & row_number)
- TextBox10.Text = Sheet1.Range("J" & row_number)
- TextBox11.Text = Sheet1.Range("K" & row_number)
- End If
- Loop Until item_in_review = ""
- End Sub
- Private Sub CommandButton3_Click()
- 'After searching data and fill the textbox in userform
- 'i will edit the data for Sheet1
- 'Search ID and other info will fill the textbox
- 'and same with other when i trying to search something and edit spicific
- 'and edit some text When click this the add , delete button willbe disable
- 'and when i click edit button the data when i edit will be save in database sheet1 it will replace the data
- End Sub
- Private Sub CommandButton4_Click()
- 'this button after searching the data in searching in textbox when i click delete
- 'all data in sheet1 and the userform textbox will be deleted
- End Sub
- Private Sub CommandButton5_Click()
- End
- End Sub
- Private Sub UserForm_Click()
- End Sub