+ Reply to Thread
Results 1 to 7 of 7

Multi Selection Listbox

Hybrid View

  1. #1
    Registered User
    Join Date
    08-12-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    25

    Multi Selection Listbox

    Hello guys,
    I am struck at some point, I searched and found many articles here but none helped me,
    My problem is I am making a listbox with multiple selection but unable to apply for loop
    I know its silly but I am really struck here, its unable to find the listbox itself don't know why??
    Please guys help me.
    I have attached my excel with it, please have a look on its code.
    Thanks
    Attached Files Attached Files
    Last edited by protocol; 08-18-2011 at 03:28 AM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Multi Selection Listbox

    Sub ListBox5_Change()
    Dim lItem As Long
    Dim appCaller As String
    
        With ActiveSheet
        
            appCaller = Application.Caller
            With .ListBoxes(appCaller)
                
                For lItem = 1 To .ListCount
            
                    If .Selected(lItem) Then
                
                        Sheet2.Range("A65536").End(xlUp)(2, 1) = .List(lItem)
                        .Selected(lItem) = False
                    End If
                Next lItem
            End With
        End With
    End Sub

  3. #3
    Registered User
    Join Date
    08-12-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Multi Selection Listbox

    wow thanks a lot guys, Though i have solved it myself but still thanks a lot to Snb and Bob. +rep for you guys
    Can you tell me how to add unique values in the above active x listbox.
    This is my code :

    Private Sub lstSpecialization_Click()
    Dim val As String
    Dim i As Integer
    Dim FinalRow As Integer
    
    
    FinalRow = Cells(rows.Count, 1).End(xlUp).Row
    
    For i = 2 To FinalRow
    Sheet2.Range("A2", Range("A65536").End(xlUp)).AdvancedFilter(xlFilterCopy, Range("A1"), Range("E2"), True)
    val = Cells(i, 1).Value
    ListBox123.AddItem (val)
    Next
    End Sub
    Last edited by protocol; 08-17-2011 at 02:30 AM.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Multi Selection Listbox

    If the original question has been solved, then mark it solved. Then sk the new question in a new thread, with a link to this one if necessary
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    08-12-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Multi Selection Listbox

    Quote Originally Posted by royUK View Post
    If the original question has been solved, then mark it solved. Then sk the new question in a new thread, with a link to this one if necessary
    Sure
    short message damn ...

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Multi Selection Listbox

    if it's an activeX-listbox, and the listbox contains a one-dimensional array:

    sub snb()
      for j=0 to sheet1.listbox1.listcount-1
        if sheet1.listbox1.selected(j) then c01 =c01 & "|" sheet1.listbox1.list(j)
      next
     
      if c01<>"" then 
        sn=split(mid(c01,2),"|")
        sheet2.cells(rows.count,1).end(xlup).offset(1).resize(ubound(sn)+1)=application.transpose(sn)
      end if
    End Sub



  7. #7
    Registered User
    Join Date
    08-12-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Multi Selection Listbox

    @Snb
    This code is giving some error, its saying Syntax error
    This is the code :

    Dim j As Long
     For j = 0 To Sheet1.ListBox1.ListCount - 1
        If Sheet3.lstSpecialization.Selected(j) Then
            c01 = c01 & "|" Sheet3.lstSpecialization.List (j)
      Next
      If c01 <> "" Then
        sn = Split(Mid(c01, 2), "|")
        Sheet2.Cells(rows.Count, 1).End(xlUp).Offset(1).Resize(UBound(sn) + 1) = Application.Transpose(sn)
      End If
    Last edited by protocol; 08-18-2011 at 03:39 AM.

+ 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