+ Reply to Thread
Results 1 to 5 of 5

2 column Listbox

Hybrid View

  1. #1
    Registered User
    Join Date
    10-29-2012
    Location
    shrewsbury
    MS-Off Ver
    Excel 2003
    Posts
    25

    2 column Listbox

    Hi All im trying to create a two column listbox that will transfer both columns to the listbox on the right and also transfer from the right to left currently right to left works but when I trasnfer from the left to right then the right to left only one column is moved.

    I have an example of my spreadsheet attached. Hope this makes sense

    Thanks in advance
    Attached Files Attached Files

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: 2 column Listbox

    Just as you added the contents of column 2 in the Initialize event, so shall you have to add those when you move it from listbox to listbox.

    E.g.
        For iCtr = 0 To Me.ListBox2.ListCount - 1
            If Me.ListBox2.Selected(iCtr) = True Then
                Me.ListBox1.AddItem Me.ListBox2.List(iCtr)
                Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = _
                    Me.ListBox2.List(iCtr, 1)
                End If
        Next iCtr
    David
    (*) Reputation points appreciated.

  3. #3
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: 2 column Listbox

    Private Sub BTN_MoveSelectedRight_Click()
    Dim ws As Worksheet
    Dim iCtr As Long
    Set ws = Worksheets("Additives")
    
        For iCtr = 0 To Me.ListBox1.ListCount - 1
            If Me.ListBox1.Selected(iCtr) = True Then
                Me.ListBox2.AddItem Me.ListBox1.List(iCtr) & " " & Me.ListBox1.List(iCtr, 1)
                End If
        Next iCtr
    
        For iCtr = Me.ListBox1.ListCount - 1 To 0 Step -1
            If Me.ListBox1.Selected(iCtr) = True Then
                Me.ListBox1.RemoveItem iCtr
            End If
        Next iCtr
    
    End Sub
    If solved remember to mark Thread as solved

  4. #4
    Registered User
    Join Date
    10-29-2012
    Location
    shrewsbury
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: 2 column Listbox

    Thank you for the reply there seems to be still one more issue rather it is merging both columns data into the 1st column rather than keeping them split out any clues to how to do this?

  5. #5
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: 2 column Listbox

    Private Sub UserForm_Initialize()
    Dim iCtr As Range
    Dim ws As Worksheet
    Set ws = Worksheets("Additives")
    For Each iCtr In ws.Range("IngID")
      With Me.ListBox1
        .AddItem iCtr.Offset(0, 1).Value
        .List(.ListCount - 1, 1) = iCtr.Offset(0, 0).Value
      End With
    Next iCtr
    Me.ListBox1.MultiSelect = fmMultiSelectMulti
    Me.ListBox2.MultiSelect = fmMultiSelectMulti
    End Sub
    Private Sub BTN_moveAllLeft_Click()
    Dim iCtr As Long
    For iCtr = 0 To Me.ListBox2.ListCount - 1
        With Me.ListBox1
          .AddItem Me.ListBox2.List(iCtr)
          .List(.ListCount - 1, 1) = Me.ListBox2.List(iCtr, 1)
        End With
    Next iCtr
    Me.ListBox2.clear
    End Sub
    Private Sub BTN_MoveSelectedLeft_Click()
    Dim ws As Worksheet
    Dim iCtr As Long
    Set ws = Worksheets("Additives")
    For iCtr = 0 To Me.ListBox2.ListCount - 1
      If Me.ListBox2.Selected(iCtr) = True Then
        With Me.ListBox1
          .AddItem Me.ListBox2.List(iCtr)
          .List(.ListCount - 1, 1) = Me.ListBox2.List(iCtr, 1)
        End With
      End If
    Next iCtr
    For iCtr = Me.ListBox2.ListCount - 1 To 0 Step -1
      If Me.ListBox2.Selected(iCtr) = True Then
        Me.ListBox2.RemoveItem iCtr
      End If
    Next iCtr
    End Sub
    Private Sub BTN_moveAllRight_Click()
    Dim iCtr As Long
    For iCtr = 0 To Me.ListBox1.ListCount - 1
        With Me.ListBox2
          .AddItem Me.ListBox1.List(iCtr)
          .List(.ListCount - 1, 1) = Me.ListBox1.List(iCtr, 1)
        End With
    Next iCtr
    Me.ListBox1.clear
    End Sub
    Private Sub BTN_MoveSelectedRight_Click()
    Dim ws As Worksheet
    Dim iCtr As Long
    Set ws = Worksheets("Additives")
    For iCtr = 0 To Me.ListBox1.ListCount - 1
      If Me.ListBox1.Selected(iCtr) = True Then
        With Me.ListBox2
          .AddItem Me.ListBox1.List(iCtr)
          .List(.ListCount - 1, 1) = Me.ListBox1.List(iCtr, 1)
        End With
      End If
    Next iCtr
    For iCtr = Me.ListBox1.ListCount - 1 To 0 Step -1
      If Me.ListBox1.Selected(iCtr) = True Then
        Me.ListBox1.RemoveItem iCtr
      End If
    Next iCtr
    End Sub
    Private Sub cmdOK_Click()
     Unload Me
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Multi Column ListBox - set output formats for each column?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-10-2020, 10:27 AM
  2. [SOLVED] Setting individual column width sizes for multi column listbox with VB2011 Mac not working
    By Nitefox in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 2
    Last Post: 01-26-2014, 06:19 PM
  3. Having problems populating a multicolumn listbox changing Listbox column with a loop.
    By Aristizabal95 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2013, 12:41 PM
  4. Populating a listbox based on column of first listbox
    By tucanj in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-13-2013, 09:26 PM
  5. Listbox to Listbox, no duplicates & submitting same UserForm data for each Listbox entry.
    By jamieswift1977 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2012, 12:18 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1