Announcement

Collapse
No announcement yet.

Listbox content transfer to single cell

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Listbox content transfer to single cell



    hi,
    I'm creating Useform with listbox which is feeded with data comeing from user inputs (texboxes). Listbox contains 4 columns. In short, I'm looking for some solution which may store all entries from listbox to single cell (concentration). I found some solutions which are working with one column, however there are multiple columns in my case. The idea is to use some separators like comma and semicolon. ";" would separate rows and "," would separate columns in same line entries.

    On the other hand, it would be good to read this data back in listbox.

  • #2
    Hi and Welcome to the Forum ...

    Regarding the data transfer from a UserForm ListBox to a worksheet ...

    Take a look at the following :

    https://www.ozgrid.com/VBA/transfer-listbox-range.htm

    Regarding the concatenation, the Concatenate() function will solve your problem ...

    Hope this will help
    If you feel like saying "Thank You" for the help received ...You can click on the "Like" icon ...just underneath ... ... in the bottom right corner ...

    Comment


    • #3
      Hello Carim,
      I reviwed that example before posting. It's not exactly what I want to achive...

      Comment


      • #4
        Hello,

        Feel free to attach your sample file ...

        This will make your whole request clearer ...

        Especially if what you want to achieve is shown as your expected result ...
        If you feel like saying "Thank You" for the help received ...You can click on the "Like" icon ...just underneath ... ... in the bottom right corner ...

        Comment


        • #5
          well, i've created code which is working with first line in listbox, however I'm struggling with proper loop through next lines. Moreover, separator between lines data should be ";".

          have a look:

          Code:
          Dim x As String
          
              
              x = ListBox1.List(0)
             
                  
                  For i = 1 To ListBox1.ColumnCount
                      x = x & ", " & ListBox1.List(0, i)
                  Next i
               
              
              
              
              Sheets("Sheet3").Range("a2").Value = x

          Comment


          • #6


            I managed to create a basic loop with comma separator only, however this solution is fine for me:

            Code:
            Dim x As String
            
              
                        
             
              
                    For r = 0 To ListBox1.ListCount - 1
                        
                    
                            For i = 1 To ListBox1.ColumnCount
                    
                        x = x & ListBox1.List(r, i - 1) & ", "
                    Next i
                 Next
            
                
                
                
                Sheets("Sheet3").Range("a2").Value = x
            do you have any idea how to reverse this action? I mean, to populate back listbox from cell. As there are comma separators only, I belive that columns number must be defined?

            Comment

            Working...
            X