Check if multiselected items in a listbox exists in cells by looping through

MSKO

New Member
Joined
May 20, 2021
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hello there.

i have 5 columns in a sheet and 5 listboxes in a userform.
The listboxes ale all set to proporty multiselect.

I would like to loop through the 5 columns and se if the cells contains one of the selected values in the listbox.
The loop should se if:
one of the selected items in listbox1 is in the cell in column1
one of the selected items in listbox2 is in the cell in column2
one of the selected items in listbox3 is in the cell in column3
one of the selected items in listbox4 is in the cell in column4
one of the selected items in listbox5 is in the cell in column5

And if they all are, then i will do some code.

i cant seem to get it to work. have done something similar but with a conbination of comboboxes and textboxes wich have only one value selected.
I ended up with a long code of AND/OR as follows:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ThisWorkbook.Worksheets(3).Activate
For Each cell In ActiveSheet.Range("AD2:AD" & Cells(Rows.Count, 30).End(xlUp).Row)
If cell.Value = "Rekvisition" And Cells(cell.Row, 10) = UserForm1.ComboBox11.Value And Cells(cell.Row, 32) = UserForm1.ComboBox20.Text And (Cells(cell.Row, 3) = UserForm1.ComboBox12.Text Or UserForm1.ComboBox12.Text = "Alle") And (Cells(cell.Row, 9) = UserForm1.ComboBox19.Text Or UserForm1.ComboBox19.Text = "Alle") And (Cells(cell.Row, 5) = UserForm1.ComboBox18.Text Or UserForm1.ComboBox18.Text = "Alle") And Cells(cell.Row, 2).Value >= txtVal1 And Cells(cell.Row, 2).Value <= txtVal2 Then

do some code

End if
Next
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

I have tried to put the selected items in each listbox in a textstring and use it in this code. But it disent work.

Hope you can help

Have a nice day out there
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
a general method for finding selected cells in a listbox is as follows
VBA Code:
With ListBox1
    For Row= 0 to .listcount - 1
        If .Selected(row) then
            ' this item has been selected
        End If
    Next Row
End With
 
Upvote 0
Thanks Diddi.
I know how to loop through each item in listbox and cels in a column. The issue is that i dont know how to evaluate a cell.value during a loop, with MULTISELECTED items in a listbox.
Can you help here?
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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