freeisgood
New Member
- Joined
- Jan 18, 2008
- Messages
- 31
Hello All,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o></o>
Codes below is for a command button of a user form (codes found on the web), for each execution of this command, items selected by users is separated by a comma. My goal is to have them separate by a break line. I added “char(10)” to line 6 "strItems = strItems & "," & Chr(10) & ListBox1.List(lngItem)". It works, with the exception that it start by a break line then entry selected by users. <o></o>
<o></o>
I am seeking help to make the necessary adjustment to remove the unnecessary break line (first one only). I am learning VBA and a quick explanation would be greatly appreciated.<o></o>
<o></o>
Code:<o></o>
Private Sub CommandButton1_Click()<o></o>
<o></o>
Dim lngItem As Long, strItems<o></o>
<o></o>
With ListBox1<o></o>
For lngItem = 0 To ListBox1.ListCount - 1<o></o>
If ListBox1.Selected(lngItem) Then<o></o>
strItems = strItems & "," & Chr(10) & ListBox1.List(lngItem) – 1<o></o>
<o></o>
End If<o></o>
Next lngItem<o></o>
End With<o></o>
<o></o>
ActiveCell.Value = Replace(strItems, ",", "", 1, 1)<o></o>
<o></o>
Unload Me<o></o>
<o></o>
End Sub<o></o>
<o></o>
Regards<o></o>
VL<o></o>
<o></o>
Codes below is for a command button of a user form (codes found on the web), for each execution of this command, items selected by users is separated by a comma. My goal is to have them separate by a break line. I added “char(10)” to line 6 "strItems = strItems & "," & Chr(10) & ListBox1.List(lngItem)". It works, with the exception that it start by a break line then entry selected by users. <o></o>
<o></o>
I am seeking help to make the necessary adjustment to remove the unnecessary break line (first one only). I am learning VBA and a quick explanation would be greatly appreciated.<o></o>
<o></o>
Code:<o></o>
Private Sub CommandButton1_Click()<o></o>
<o></o>
Dim lngItem As Long, strItems<o></o>
<o></o>
With ListBox1<o></o>
For lngItem = 0 To ListBox1.ListCount - 1<o></o>
If ListBox1.Selected(lngItem) Then<o></o>
strItems = strItems & "," & Chr(10) & ListBox1.List(lngItem) – 1<o></o>
<o></o>
End If<o></o>
Next lngItem<o></o>
End With<o></o>
<o></o>
ActiveCell.Value = Replace(strItems, ",", "", 1, 1)<o></o>
<o></o>
Unload Me<o></o>
<o></o>
End Sub<o></o>
<o></o>
Regards<o></o>
VL<o></o>