Question

I have a ListBox in a userform that has items populated in it.

What I would like to do is add all of the items to a string seperated by a semicolon.

So far I have the following code:

For i = 0 To Me.lbSend.ListCount - 1
    Set strEmail = ws.Range("A:A").Find(What:="Me.lbSend.List(i)", LookAt:=xlWhole, MatchCase:=False, SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
    strTo = strTo & ";" & strEmail.Offset(0,1).Value
Next i

However, it is not working and I can't quite put my finger on why.

For each item in the list I need to find it in Column A in another worksheet and then add the value in the cell to the right of it to the string.

Was it helpful?

Solution

For anyone else that requires that same answer:

@tigeravatar spotted the mistake and is correct with the following: (No quotes around Me.lbSend.List(i))

For i = 0 To Me.lbSend.ListCount - 1
Set strEmail = ws.Range("A:A").Find(What:=Me.lbSend.List(i), LookAt:=xlWhole, MatchCase:=False, SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
strTo = strTo & ";" & strEmail.Offset(0,1).Value
Next i
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top