0

I have a Userform where people loop through and add on each click an item to a listbox. By clicking another buttom the items should be converted to a string with a comma as delimiter.

lstDatabase.AddItem txtfruit.Value

I tried to convert the listbox to an array and then to a string but this seems not to work

Dim deliverynoteArray() As Variant
Dim deliverynote_list As String

deliverynoteArray = lstDatabase.List
deliverynote_list = Join(deliverynoteArray, ",")

The "add" and the "convert" are both in Private Sub _click sections. Might that be the problem? That the data is not accessible?

2
  • "seems not to work" - always useful to explain what it does instead of work. Commented Apr 6, 2022 at 16:19
  • See: stackoverflow.com/a/44457705/478884 Commented Apr 6, 2022 at 16:36

1 Answer 1

1

When use deliverynoteArray = lstDatabase.List the code will create a 2D array, and Join works only on 1D arrays. So, after placing the list box element in the array you should use Transpose, which transforms a 2D array having multiple rows and one column, in a 1D type.

Try replacing deliverynote_list = Join(deliverynoteArray, ",") with:

   deliverynote_list = Join(Application.Transpose(deliverynoteArray), ",")
   Debug.Print deliverynote_list 'just to see it in Immediate Window...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.