Delete a row from a listbox and worksheet simultaneously and bring up row below

kalumbair

New Member
Joined
Aug 2, 2018
Messages
35
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.

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

 
Dante,

the listbox index was accidently changed from 2 to 1. once i realized that and put it back to 2, it works as it should. sorry for the confusion. thank you again.

K
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Dante,

The listbox index was accidently changed from 2 to 1, once I changed it back to 1 it works as it should. sorry for the confusion. thanks again

K
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top