Hello Everyone,
I could really use some help with my userform andlistbox. I have a userform that containsa listbox with several lines of data. When the user double clicks on a row in the listbox, it populates aseries of textboxes below. The userformalso has all the basic buttons, Delete, Add, Refresh and so on. What I’d like to do is when the user selectsa button it will carry out a particular function.
Right now I’m struggling with the Delete button as I keepgetting an error messages no matter how much I adjust the code. Ultimately, what I want to do is when theDelete button is clicked the data that is in the textboxes will delete from thelistbox and worksheet as well, and bottom rows of data will come up and fill up the listboxand worksheet. The data starts on B3 to goes to J35. If anyone can help outwith this, I’d really appreciate it. Here is the code I have so far, thank you in advance.
I could really use some help with my userform andlistbox. I have a userform that containsa listbox with several lines of data. When the user double clicks on a row in the listbox, it populates aseries of textboxes below. The userformalso has all the basic buttons, Delete, Add, Refresh and so on. What I’d like to do is when the user selectsa button it will carry out a particular function.
Right now I’m struggling with the Delete button as I keepgetting an error messages no matter how much I adjust the code. Ultimately, what I want to do is when theDelete button is clicked the data that is in the textboxes will delete from thelistbox and worksheet as well, and bottom rows of data will come up and fill up the listboxand worksheet. The data starts on B3 to goes to J35. If anyone can help outwith this, I’d really appreciate it. Here is the code I have so far, thank you in advance.
Code:
Private Sub CommandButton1_Click()
Dim currentrow As Long
Answer = MsgBox("are you sure you want to delete this record?", vbYesNo, "Delete Record")
If Answer = vbYes Then
Cells(currentrow, 3).EntireRow.Delete
End If
End Sub
Private Sub UserForm_Initialize()
currentrow = 3
TextBox1 = Cells(currentrow, 1)
TextBox2 = Cells(currentrow, 2)
TextBox3 = Cells(currentrow, 3)
TextBox1 = Cells(currentrow, 4)
TextBox2 = Cells(currentrow, 6)
TextBox3 = Cells(currentrow, 7)
TextBox2 = Cells(currentrow, 8)
TextBox3 = Cells(currentrow, 9)
End Sub