Hey all,
First post, hoping someone can help! I've been going at this for a while now:
My original goal was to create a dropdown multi-select listbox with check boxes. I have about 20 selections going into the list box and didn't want to see the selections until I selected the cell and dropped a list down. I've essentially made it there, but I'm hung up on one thing. Once I click into the cell, make my selections in the listbox, then click out of the cell that contains the list box and click back into it, the checked selections I've made have disappeared.
The code below is what I'm using to make the listbox appear when the cell is selected and to hide it when the cell is not selected. Further details and visual aids can be found at this site: Checkboxes for multiple values in a single cell in Excel - Stack Overflow
Thanks in advance for any help!
Option Explicit
Dim fillRng As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim LBColors As MSForms.ListBox
Dim LBobj As OLEObject
Dim i As Long
Set LBobj = Me.OLEObjects("LB_Colors")
Set LBColors = LBobj.Object
If Not Intersect(Target, [B2]) Is Nothing Then
Set fillRng = Target
With LBobj
.Left = fillRng.Left
.Top = fillRng.Top
.Width = fillRng.Width
.Visible = True
End With
Else
LBobj.Visible = False
If Not fillRng Is Nothing Then
fillRng.ClearContents
With LBColors
If .ListCount <> 0 Then
For i = 0 To .ListCount - 1
If fillRng.Value = "" Then
If .Selected(i) Then fillRng.Value = .List(i)
Else
If .Selected(i) Then fillRng.Value = _
fillRng.Value & "," & .List(i)
End If
Next
End If
For i = 0 To .ListCount - 1
.Selected(i) = False
Next
End With
Set fillRng = Nothing
End If
End If
End Sub
First post, hoping someone can help! I've been going at this for a while now:
My original goal was to create a dropdown multi-select listbox with check boxes. I have about 20 selections going into the list box and didn't want to see the selections until I selected the cell and dropped a list down. I've essentially made it there, but I'm hung up on one thing. Once I click into the cell, make my selections in the listbox, then click out of the cell that contains the list box and click back into it, the checked selections I've made have disappeared.
The code below is what I'm using to make the listbox appear when the cell is selected and to hide it when the cell is not selected. Further details and visual aids can be found at this site: Checkboxes for multiple values in a single cell in Excel - Stack Overflow
Thanks in advance for any help!
Option Explicit
Dim fillRng As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim LBColors As MSForms.ListBox
Dim LBobj As OLEObject
Dim i As Long
Set LBobj = Me.OLEObjects("LB_Colors")
Set LBColors = LBobj.Object
If Not Intersect(Target, [B2]) Is Nothing Then
Set fillRng = Target
With LBobj
.Left = fillRng.Left
.Top = fillRng.Top
.Width = fillRng.Width
.Visible = True
End With
Else
LBobj.Visible = False
If Not fillRng Is Nothing Then
fillRng.ClearContents
With LBColors
If .ListCount <> 0 Then
For i = 0 To .ListCount - 1
If fillRng.Value = "" Then
If .Selected(i) Then fillRng.Value = .List(i)
Else
If .Selected(i) Then fillRng.Value = _
fillRng.Value & "," & .List(i)
End If
Next
End If
For i = 0 To .ListCount - 1
.Selected(i) = False
Next
End With
Set fillRng = Nothing
End If
End If
End Sub