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
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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