Making Listbox selection to also clear Textbox values that dont apply

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,983
Office Version
  1. 2007
Platform
  1. Windows
Code shown below in use & works well BUT i wish to slightly expand on it.

Currently this works fine,
When a Listbox selection is made the colour selected is shown only & the others are cleared

This is the part i would like to also be added,
Upon making a colour selection clear the Textbox values mentioned that are not that selected colour & to only show that colours count value.

Basically if the Value selected is RED then i only need to see the value count for RED in its Textbox & make others 0
Same applies for another the colours when selected.

Currently when used im seeing values for all colours, see SCREEN SHOT EXAMPLE


VBA Code:
Private Sub ListBox1_Click()
    Dim i As Long
    Dim colour As String
   
    colour = ListBox1.List(ListBox1.ListIndex, 3)
    For i = ListBox1.ListCount - 1 To 0 Step -1
        If ListBox1.List(i, 3) <> colour Then
            ListBox1.RemoveItem (i)
        End If
    Next i
   
End Sub

Thanks to @NoSparks for the original code supplied above.

Please advise correct code Thanks.






EaseUS_2025_02_28_10_16_36.jpg
 
Apologies my mistake.
I checked it from the code window as opposed from the sheet.

Works fine.
Thanks.

I was in a rush to get out.
 
Upvote 0
No problem, you now know why it was like that.
I guess post 3 is the solution to the original request but it would be post 8 if you take into account the simplifying of what was needed.


There is a saying.... Engineers don't make mistakes, they make revisions.
 
Upvote 0

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