+ Reply to Thread
Results 1 to 6 of 6

Transfer Item From Range1 to Range2 Using ListBox

Hybrid View

  1. #1
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Transfer Item From Range1 to Range2 Using ListBox

    Hi, As it is not clear where "Range1" and "Range2" are I have Based this on the Ranges in Columns "A" & "B". When you have got it working change the related Addresses to suit your ranges.
    If you Show the Userform In "Edit Mode" then Double click on the Userform. You Can paste the entire Codes Below into that Module.
    When you select an Item in Either ListBox, it will be deleted from its related range and Listbox and insert in the Other Range and ListBox.
    Private Sub ListBox1_Click()
    Dim rng, rngB, sert, SertB
    Dim Last As Integer
    Last = Range("B" & Rows.Count).End(xlUp).Row
    
    Cells(ListBox1.ListIndex + 1, "A").Delete shift:=xlUp
    Cells(Last + 1, "B").Value = ListBox1.Value
    
    rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
    rngB = Range(Range("B1"), Range("B" & Rows.Count).End(xlUp))
    
    Me.ListBox1.Clear
    Me.ListBox2.Clear
    
    For sert = 1 To UBound(rng)
        With ListBox1
            .AddItem rng(sert, 1)
        End With
    Next sert
    For SertB = 1 To UBound(rngB)
        With ListBox2
            .AddItem rngB(SertB, 1)
        End With
    Next SertB
    End Sub
    '''''''''''''''''
    Private Sub ListBox2_Click()
    Dim rng, rngB, sert, SertB
    Dim Last As Integer
    Last = Range("A" & Rows.Count).End(xlUp).Row
    
    Cells(ListBox2.ListIndex + 1, "B").Delete shift:=xlUp
    Cells(Last + 1, "A").Value = ListBox2.Value
    
    rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
    rngB = Range(Range("B1"), Range("B" & Rows.Count).End(xlUp))
    
    Me.ListBox1.Clear
    Me.ListBox2.Clear
    
    For sert = 1 To UBound(rng)
        With ListBox1
            .AddItem rng(sert, 1)
        End With
    Next sert
    For SertB = 1 To UBound(rngB)
        With ListBox2
            .AddItem rngB(SertB, 1)
        End With
    Next SertB
    End Sub
    ''''''''''''''''''
    Private Sub UserForm_Initialize()
    Dim rng, Rng2
     rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
      Rng2 = Range(Range("B1"), Range("B" & Rows.Count).End(xlUp))
        ListBox1.List = rng
           ListBox2.List = Rng2
    
    End Sub
    Regards Mick

  2. #2
    Registered User
    Join Date
    03-27-2009
    Location
    Surat,India
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Transfer Item From Range1 to Range2 Using ListBox

    Dear Mickg,

    Thanks fo it! It's working me. If I want to use for Multi Column List Box then How to use it.

    Regards,

    Vishnu

  3. #3
    Registered User
    Join Date
    03-27-2009
    Location
    Surat,India
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Transfer Item From Range1 to Range2 Using ListBox

    Again Some Problems.

    How to use column headings? And I am not able to transfer all items from Range1 to Range2. At least 2 item should be there in both the ranges to run the code. Please resolve this issue.

    Regards,

    Vishnu

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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