+ Reply to Thread
Results 1 to 6 of 6

Copy one listbox item to same index position in another listbox

  1. #1
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Copy one listbox item to same index position in another listbox

    Hi,

    Is it possible to copy a list box value to another list box to the same index position.

    Example in list box 1 we have 4 items

    Name 1
    Name 2
    Name 3
    Name 4

    I would like to copy Name 3 to same position in List box 2

    blank
    blank
    Name 3
    blank

    Thanks
    Lionel
    Last edited by Foreverlearning; 05-19-2012 at 06:05 AM.

  2. #2
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Copy one listbox item to same index position in another listbox

    Hi Learning,

    Consider the following. We'll simply pass the 3rd index position (2 in the code as indexes start at zero) of LB1 to a string, and pass that string into the AddItem of same position in LB2. Hope this helps,

    Please Login or Register  to view this content.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Copy one listbox item to same index position in another listbox

    Assuming userform with 2 listboxes and a commandbutton.

    Add code to userform code module.
    Please Login or Register  to view this content.
    If you need to insert within the list rather than overwrite existing entry look at the AddItem method and it's optional second argument which specifys the position
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Copy one listbox item to same index position in another listbox

    Hi Guys,

    Thanks for the responses. Now I know it can work.

    The idea I now have is if I click on say item 3 in list box 1 and click the index position on list box 2 it would place the value
    of list box 1 in that position.

    Can this be achieved?

    Thanks
    Lionel

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Copy one listbox item to same index position in another listbox

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Copy one listbox item to same index position in another listbox

    Thanks Andy I can build on this.
    A variation of your previous post

    Lionel

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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