+ Reply to Thread
Results 1 to 3 of 3

Listbox import other worksheet multiple ranges

Hybrid View

feroguz Listbox import other... 04-17-2013, 07:40 PM
AlphaFrog Re: Listbox import other... 04-17-2013, 08:06 PM
feroguz Re: Listbox import other... 04-17-2013, 08:29 PM
  1. #1
    Registered User
    Join Date
    06-06-2012
    Location
    Mexico
    MS-Off Ver
    Excel 2010
    Posts
    99

    Lightbulb Listbox import other worksheet multiple ranges

    Hi excel Forum friend's!


    I have the following macro:

    I want that amount ranges "A2:D" (Multiple range), but only shows me the 1st column ("A"),

    When make changes, I get only first value in column listbox, not the 4 columns that I need ..

    someone could help me?
    Thank you!
    Best Regards!!


    Dim ListItems As Variant, i As Integer
    Dim SourceWB As Workbook
        With Me.ListBox2
            .Clear ' remove existing entries from the listbox
            ' turn screen updating off,
            ' prevent the user from seeing the source workbook being opened
            Application.ScreenUpdating = False
            ' open the source workbook as ReadOnly
            Set SourceWB = Workbooks.Open("C:\ICO\ICO_Import_template.xls", _
                False, True)
            ListItems = SourceWB.Worksheets(1).Range("A2:D").Value
            ' get the values you want
            SourceWB.Close False ' close the source workbook without saving changes
            Set SourceWB = Nothing
            ListItems = Application.WorksheetFunction.Transpose(ListItems)
            ' convert values to a vertical array
            For i = 1 To UBound(ListItems)
                .AddItem ListItems(i) ' populate the listbox
                
                
            Next i
            .ListIndex = -1 ' no items selected, set to 0 to select the first item
            Application.ScreenUpdating = True
        End With

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Listbox import other worksheet multiple ranges

    Range "A2:D" is not a valid range reference.

    Try something like this...
        Dim vListItems As Variant
        
        ' turn screen updating off,
        ' prevent the user from seeing the source workbook being opened
        Application.ScreenUpdating = False
        ' open the source workbook as ReadOnly
        With Workbooks.Open("C:\ICO\ICO_Import_template.xls", False, True)
            With .Worksheets(1)
                'Range A2 to last used row in column D
                vListItems = .Range("A2", .Range("D" & Rows.Count).End(xlUp)).Value
            End With
            .Close False ' close the source workbook without saving changes
        End With
        
        With Me.ListBox2
            .Clear ' remove existing entries from the listbox
            .ColumnCount = 4
            .ColumnWidths = "50;60;50;40"  'adjust to suit
            .List = vListItems
            .ListIndex = -1 ' no items selected, set to 0 to select the first item
        End With
        Application.ScreenUpdating = True

  3. #3
    Registered User
    Join Date
    06-06-2012
    Location
    Mexico
    MS-Off Ver
    Excel 2010
    Posts
    99

    Re: Listbox import other worksheet multiple ranges

    Great Job!!.. thanks again AlphaFrog!..

    Best Regards!

+ 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