+ Reply to Thread
Results 1 to 3 of 3

Excel VBA Listbox

  1. #1
    Registered User
    Join Date
    06-25-2006
    Posts
    2

    Excel VBA Listbox

    Hi All,

    I have created a Listbox on a Userform. the Listbox properties are as folows:

    Name: SectorList
    MultiSelect: fmMultiSelectMulti

    I am trying to see which items were selected and then for these items i want to put their value into a cell. My problem is that once it finds the first item that was selected, it puts its value into the relevant cell but then seems to mark all the other selected items as not selected.

    The weird thing is, for testing purposes, if i dont actually assign the selected items value to a cell then there is no problems!

    The code is as follows:

    For lItem = 0 To sectorList.ListCount - 1
    If sectorList.Selected(lItem) Then
    ActiveCell.Value = sectorList.List(lItem)
    ActiveCell.Offset(1, 0).Range("A1").Select
    End If
    Next

    Any help would be really appreciated!

    Shakeel

  2. #2
    Chip Pearson
    Guest

    Re: Excel VBA Listbox

    Your code works as expected for me.


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com

    "shakeel_sadiq"
    <shakeel_sadiq.29yzio_1151259002.8718@excelforum-nospam.com>
    wrote in message
    news:shakeel_sadiq.29yzio_1151259002.8718@excelforum-nospam.com...
    >
    > Hi All,
    >
    > I have created a Listbox on a Userform. the Listbox properties
    > are as
    > folows:
    >
    > Name: SectorList
    > MultiSelect: fmMultiSelectMulti
    >
    > I am trying to see which items were selected and then for these
    > items i
    > want to put their value into a cell. My problem is that once it
    > finds
    > the first item that was selected, it puts its value into the
    > relevant
    > cell but then seems to mark all the other selected items as not
    > selected.
    >
    > The weird thing is, for testing purposes, if i dont actually
    > assign the
    > selected items value to a cell then there is no problems!
    >
    > The code is as follows:
    >
    > For lItem = 0 To sectorList.ListCount - 1
    > If sectorList.Selected(lItem) Then
    > ActiveCell.Value = sectorList.List(lItem)
    > ActiveCell.Offset(1, 0).Range("A1").Select
    > End If
    > Next
    >
    > Any help would be really appreciated!
    >
    > Shakeel
    >
    >
    > --
    > shakeel_sadiq
    > ------------------------------------------------------------------------
    > shakeel_sadiq's Profile:
    > http://www.excelforum.com/member.php...o&userid=35764
    > View this thread:
    > http://www.excelforum.com/showthread...hreadid=555386
    >




  3. #3
    Registered User
    Join Date
    06-25-2006
    Posts
    2
    Thanks for checking it Chip

    Ive ended up creating a temporary listbox and adding the selected values into it then reading of this new userlist.

    so the problem is solved though as youve said, there shouldnt have been one!

    Ta.

+ 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