+ Reply to Thread
Results 1 to 4 of 4

Populating Listbox in a Userform with a named range from another sheet

Hybrid View

gruberm Populating Listbox in a... 04-02-2013, 06:38 AM
Kyle123 Re: Populating Listbox in a... 04-02-2013, 06:43 AM
JosephP Re: Populating Listbox in a... 04-02-2013, 06:47 AM
gruberm Re: Populating Listbox in a... 04-02-2013, 06:48 AM
  1. #1
    Registered User
    Join Date
    11-05-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Populating Listbox in a Userform with a named range from another sheet

    Hello All and thank you for any help you may be able to offer in advance. The code I've placed below is called from a macro on a different sheet (Framing Tool) and is meant to first determine the size of a list, make that list into a range, and then place the range as the options in a listbox. However the code is creating the range from the current sheet rather than WsOppDB and I cannot figure out why, any thoughts?

    Also, I'm having trouble understanding the difference between .list and .rowsource.

    Private Sub UserForm_Initialize()
    
    Dim wsOppDB, wsframingtool As Worksheet
    Dim OpprangeList As Range
    Dim opprangenumber As Integer
    
    Set wsOppDB = Sheets("OpportunitiesDB")
    Set wsframingtool = Sheets("Framing Tool")
    
    opprangenumber = Application.WorksheetFunction.CountA(wsOppDB.Range("C11:C500"))
    
    With wsOppDB
    Set OpprangeList = Range(Cells(11, 3), Cells(11 + opprangenumber - 1, 3))
    End With
    
    With OpportunityList
        .List = OpprangeList.Value
    End With
    'MsgBox opprangenumber
    End Sub
    Last edited by gruberm; 04-02-2013 at 06:49 AM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Populating Listbox in a Userform with a named range from another sheet

    With wsOppDB
        Set OpprangeList = .Range(.Cells(11, 3), .Cells(11 + opprangenumber - 1, 3))
    End With
    Rowsource is pretty horrible and inflexible, stick with list

    Rowsource binds the control to the data, whereas list is just a copy of the data in an array form.

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Populating Listbox in a Userform with a named range from another sheet

    you're missing some periods
    With wsOppDB
        Set OpprangeList = .Range(.Cells(11, 3), .Cells(11 + opprangenumber - 1, 3))
    End With
    also note that
    Dim wsOppDB, wsframingtool As Worksheet
    ought to be
    Dim wsOppDB as worksheet, wsframingtool As Worksheet
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Registered User
    Join Date
    11-05-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Populating Listbox in a Userform with a named range from another sheet

    Thank you very much Kyle and Joseph

+ 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