timanddez1
New Member
- Joined
- May 23, 2018
- Messages
- 1
When I change: gCellCurrVal = gCellCurrVal & "," & Me.ListBox1.List(ii) to this: gCellCurrVal = gCellCurrVal & vbNewLine & Me.ListBox1.List(ii) in the code below, rather than just changing the way the selected values are represented (separated by a new line instead of separated by coma) the values selected are no longer remembered. Each time I revisit the cell, I have to select the values again to prevent them from disappearing. How do I change the code so that the selected values are remembered each time I revisit the cell?
Private Sub CommandButton1_Click()
UserForm1.Hide 'Pop up the form
End Sub
Private Sub CommandButton2_Click()
For ii = 0 To ListBox1.ListCount - 1
Me.ListBox1.Selected(ii) = False
Next ii
End Sub
Private Sub CommandButton3_Click()
For ii = 0 To ListBox1.ListCount - 1
Me.ListBox1.Selected(ii) = True
Next ii
End Sub
Private Sub CommandButton4_Click()
gCellCurrVal = ""
For ii = 0 To ListBox1.ListCount - 1
If Me.ListBox1.Selected(ii) = True Then
If gCellCurrVal = "" Then
gCellCurrVal = Me.ListBox1.List(ii)
Else
gCellCurrVal = gCellCurrVal & "," & Me.ListBox1.List(ii)
End If
End If
Next ii
UserForm1.Hide
End Sub
Private Sub UserForm_Activate()
On Error Resume Next
'On each activation, clear the whole,
'then add every country list element as blank
Me.ListBox1.Clear
For Each element In gCountryListArr
Me.ListBox1.AddItem element
Next element
UserForm_initialize
End Sub
Private Sub UserForm_initialize()
For Each element In Split(gCellCurrVal, ",")
For ii = 0 To ListBox1.ListCount - 1
If element = Me.ListBox1.List(ii) Then
Me.ListBox1.Selected(ii) = True
End If
Next ii
Next element
End Sub
Private Sub CommandButton1_Click()
UserForm1.Hide 'Pop up the form
End Sub
Private Sub CommandButton2_Click()
For ii = 0 To ListBox1.ListCount - 1
Me.ListBox1.Selected(ii) = False
Next ii
End Sub
Private Sub CommandButton3_Click()
For ii = 0 To ListBox1.ListCount - 1
Me.ListBox1.Selected(ii) = True
Next ii
End Sub
Private Sub CommandButton4_Click()
gCellCurrVal = ""
For ii = 0 To ListBox1.ListCount - 1
If Me.ListBox1.Selected(ii) = True Then
If gCellCurrVal = "" Then
gCellCurrVal = Me.ListBox1.List(ii)
Else
gCellCurrVal = gCellCurrVal & "," & Me.ListBox1.List(ii)
End If
End If
Next ii
UserForm1.Hide
End Sub
Private Sub UserForm_Activate()
On Error Resume Next
'On each activation, clear the whole,
'then add every country list element as blank
Me.ListBox1.Clear
For Each element In gCountryListArr
Me.ListBox1.AddItem element
Next element
UserForm_initialize
End Sub
Private Sub UserForm_initialize()
For Each element In Split(gCellCurrVal, ",")
For ii = 0 To ListBox1.ListCount - 1
If element = Me.ListBox1.List(ii) Then
Me.ListBox1.Selected(ii) = True
End If
Next ii
Next element
End Sub