Remove Table Row From Userform

Enjoylyfe

New Member
Joined
Apr 29, 2020
Messages
17
Office Version
  1. 365
Platform
  1. Windows
I have made a userform for deleting a row of data. Is it possible when i delete a row of data, the only row affected is the table row, while the same row outside the table is not deleted?

For example, if want to remove Bill, test1, and 345, is it possible to make the data1 still remain there and not removed?

1588178674056.jpg
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You can use something like
VBA Code:
   With ActiveSheet.ListObjects("Table1").DataBodyRange
      .Rows(3).Delete
   End With
 
Upvote 0
Hi there,

Cross-posted: Delete Table Row From Userform

Answering for posterity. If you load the data in your userform, I'm assuming into a ListBox control, as an array and not sourced directly to the Table data, then yes you can do that. You'd basically loop through your listbox data (array), find any selected item, and remove it with the RemoveItem method. Here is an example:

VBA Code:
Private Sub CommandButton1_Click()

    Dim Index As Long
    Dim RemoveRow As Long
    Dim Values As Variant

    Values = Me.ListBox1.List
    RemoveRow = -1
   
    For Index = 0 To Me.ListBox1.ListCount - 1
        If Me.ListBox1.Selected(Index) Then
            RemoveRow = Index
            Exit For
        End If
    Next Index
   
    If RemoveRow = -1 Then Exit Sub
    Me.ListBox1.RemoveItem RemoveRow
   
End Sub

If you wanted to actually remove the Table row, and not in the userform only first, you would replace this line:

VBA Code:
Me.ListBox1.RemoveItem RemoveRow

With these lines:

VBA Code:
ThisWorkbook.Worksheets("Sheet3").ListObjects("Table2").ListRows(RemoveRow + 1).Delete
Me.ListBox1.List = ThisWorkbook.Worksheets("Sheet3").ListObjects("Table2").DataBodyRange.Value

Again, changing the sheet/Table names to suit.
 
Last edited:
Upvote 0
Hello, i have this code but it delete the entire row instead of the table row only. Could you please help me to modify my code?

VBA Code:
Private Sub CommandButton5_Click()
    Dim profile_id As String
    profile_id = ComboBox9.value
    Lastrow = Sheets("Profile").Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To Lastrow
    If Sheets("Profile").Cells(i, 1).value = profile_id Then
    Sheets("Profile").Rows(i).Delete
    Unload Me
    MsgBox "Your data has been deleted", vbOKOnly, "Successful"
    End If
    Next
End Sub
 
Upvote 0
Anyway i have tried the code you guys had given but maybe i modify the code wrong so it couldnt run perfectly
 
Upvote 0
What is the name of the table?
 
Upvote 0
Glad you have got it working & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

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