Multi select Listbox loses all selections after first loop

YveHill

New Member
Joined
May 26, 2011
Messages
2
I have a user form with 2 multi select listboxes populated with named ranges. The first works fine and loops through all the selected scouts. I can select multiple items in the second list (ReqList) and it will find the first selected item, execute the code to write a value correctly then loop through as if no other items were selected. When I break the code and go look at the form, there are no highlighted items after the first for/next statement. How is ReqList getting deselected? Thank you for your help in advance.

Code:
Private Sub SaveButton_Click()
    Set ws = Worksheets("Summary")
    For NumScout = 0 To ScoutList.ListCount - 1
          If ScoutList.Selected(NumScout) = True Then
                For numreq = 0 To ReqList.ListCount - 1
                    scoutcolumn = NumScout + 3
                    If ReqList.Selected(numreq) = True Then
                        ws.Range("Scout").Cells(numreq + 1, scoutcolumn).Value = "A"
                        ReqList.Selected(NumReq) = False
                    End If
                Next
          Else
          ScoutList.Selected(NumScout) = False
    Next
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Problem solved. I was populating my list with a named array and when I wrote the first value back using that same name reference to that array it deselected the items. I created a second named array to use when writing the value back and then it keeps the selections.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,756
Members
452,940
Latest member
rootytrip

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