+ Reply to Thread
Results 1 to 7 of 7

Range Error

  1. #1
    Registered User
    Join Date
    07-26-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    4

    Range Error

    I'm trying to Populate a ListBox's RowSource dynamically from different worksheet
    Please Login or Register  to view this content.
    The message on run is
    subscript out of range
    on the line
    Please Login or Register  to view this content.
    That range should be A4:A11

    When I substitute that literal
    Please Login or Register  to view this content.
    , I get the same error.

    Same result when I substitute bang (!Range) in place of the .Range

    The reference tab: (name) shtReference; Name Reference (I've used both "Reference" and "shtReference" -- same result)
    The basedata tab: (name) shtBaseData; Name BaseData (I've used both names -- but it never gets to that code)

    Another curiosity is the the Sub Name is "UserForm" when the form's name is frmMaintain.

    Regards,

    grNadpa
    Last edited by grNadpa; 08-13-2012 at 08:15 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Range Error

    Hi,

    It appears that you haven't got Option Explicit set. This forces you to declare variable names.
    You've declared
    rngCustomerName As Range

    but are trying to set
    rngCustomerNam

    It's always good practice to use Option Explicit to avoid this very problem.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-26-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    4

    Populate Listbox from separate worksheet

    Thanks to Richard Buttery, the range spec is fixed. But still unable to populate my listbox.
    Please Login or Register  to view this content.
    Message:
    Object does not support this property or method
    on line
    Please Login or Register  to view this content.
    Probably obvious, but I don't see it.

    Regards,

    grNadpa

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Range Error

    Where is your listbox? On the userform or on the sheet?
    David
    (*) Reputation points appreciated.

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

    Re: Populate Listbox from separate worksheet

    Try this

    Please Login or Register  to view this content.
    Worksheets("BaseData") has nothing to do with the UserForm.
    Hope that helps.

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

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    07-26-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Range Error

    That does the trick.

    So let me see if I understand.
    The "Me" references the active form.
    The "rngCustomerName.Address" provides the specific property of the range that ".RowSource" expects [which is why I got my error?] and
    The "(external:=True)" specifies that the rngCustomerName.Address is not within the current sheet?

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

    Re: Range Error

    You are right, but for the RowSource Excel VBA expects a String not a Range, therefore use .Address which will return a String

+ 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