+ Reply to Thread
Results 1 to 4 of 4

List of items in a userform listbox, object required error in code

  1. #1
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    List of items in a userform listbox, object required error in code

    Hi,

    I'm attempting modify some code from one userform to a new one, using different cell references from the original macro. I'm working at a level where I am beginning to understand VBA functions but I admit that this code is just a little bit beyond my understanding (it was previously given to me in this forum to help with the first listbox I put together).

    I've changed the code as best I can and am getting a "424 Object Required" error, where the ## is in the code below.

    I'm happy to give more detail as to the thing i'm trying to do but briefly, the user will change a combobox called CB_Name, then the code runs which will look for all the times that name is mentioned in COL P (of another sheet, not the activesheet), then list all of the Items in col B rows that contain that name. The current code below does this by using the "find" feature that excel has and using an offset of -14 columns after the initial "find all of that name" part - I think i've changed the cell references correctly but i can't think of why a previously working code has this error now.

    Please Login or Register  to view this content.
    Last edited by jayherring86; 01-09-2015 at 05:45 PM.

  2. #2
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: List of items in a userform listbox, object required error in code

    I solved this problem myself, but don't know how to delete the thread.

    As it turns out, the solution was simple. I reference a "CB_Name" in the code, which is a ComboBox that is to contain the name I want to search for. When the userform initialises, the CB_Name box is loaded with the word "name" which is taken from cell P2. the above code starts looking from cell P3 so it can't highlight any cells - causing the object error.

    To fix the code, all i had to do was change the "Range("p3:p"... " to " Range("p2:p" ... " and the code runs fine.

    If an admin can delete this thread then that would be fine.

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: List of items in a userform listbox, object required error in code

    Hi Jay,

    VBA thinks your variable is type 'Variant' which can masquerade as any type, but apparently not as an uninitialized range as you have discovered. You need to let VBA know the TYPE for each variable you are using. You accomplish this in two ways:
    a. Use 'Option Explicit' at the top of each module to FORCE variable type declation.
    b. Use a dim statement (or equivalent) to let Excel know the type of each variable

    Try running the following three procedures in it's own code module. 'Option Explicit' must be at the top of the module. Run it as is with 'Option Explicit' commented out. Then run the procedures with 'Option Explicit' activated.
    Please Login or Register  to view this content.
    To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. dim i as Integer). http://www.cpearson.com/excel/DeclaringVariables.aspx

    The following is a pretty good tutorial on Data Types:
    http://www.functionx.com/vbaexcel/Lesson03.htm

    The following is the best tutorial I've seen on ranges:
    http://www.globaliconnect.com/excel/...=79&Itemid=475

    --------------------

    Please feel free to continue this thread if my response does not answer your question. If your question is answered, please mark the thread as solved. If you have additional questions about the same code, don't use this thread, but start a new one.

    I hope I've helped.

    Lewis

  4. #4
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: List of items in a userform listbox, object required error in code

    Thank you so much for showing me this, I feel like it's put me on to something i can really learn from.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] 424 Object required error when calling a UserForm from another
    By rybussell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2013, 01:16 PM
  2. [SOLVED] Why 'object required' error from this code?
    By vizzkid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2013, 09:35 AM
  3. [SOLVED] Items in Userform Listbox are wider than list box. Need to see all character of item
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2012, 06:40 AM
  4. Compile error : object required in userform
    By asha3010 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2010, 04:08 AM
  5. Error 424 Object Required Error when Using AddItem to ListBox Generated in Code
    By jclark419 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2010, 12:47 PM

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