delete not selected items from listbox based on selected item without delete from sheet

leap out

Active Member
Joined
Dec 4, 2020
Messages
271
Office Version
  1. 2016
  2. 2010
Hello guys
In fact, my topic is different from the rest of the usual topics, and I certainly did not find any topic like mine. What I searched for is that all the elements are not selected should delete them , provided that they are before the selected element. As for the not selected elements that locate after the selected element, they must remain as they are without deletion .
note: it must just delete from listbox ,not from sheet

here is my file to see closely
DELETE .xlsm
first picture whether show the data on userform or search by textbox
1.JPG


second sheet when select specific item
2.JPG

then should delete all of items before selected item from listbox, should not delete from sheet at all .
3.JPG

thanks in advance .
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Replace your CommandButton1 code with this:

VBA Code:
Private Sub CommandButton1_Click()
  Dim i As Long
  For i = ListBox1.ListIndex - 1 To 1 Step -1
    ListBox1.RemoveItem i
  Next i
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

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