+ Reply to Thread
Results 1 to 7 of 7

search method of range class failed

  1. #1
    Registered User
    Join Date
    10-28-2007
    Posts
    6

    search method of range class failed

    Hi,

    I'm new to vb - and have been working on this project for a couply of weeks -
    i'm trying to fill my listbox2 on worksheet2 based on selection in a listbox1 on worksheet1

    this code worked for me at first
    but it stops working after awhile

    I've tried all the methods i've seen online - including making this a macro and calling the macro when the listbox is selected

    i've also tried all sorts of ways , including the method
    Please Login or Register  to view this content.
    instead of activate

    my code's below - the area in red is the problem one

    PLEASE HELP !! thanks !


    Please Login or Register  to view this content.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Selecting or Activating the worksheet is not necessary. It would be more efficient to use the ListFillRange of the Listbox than looping through cells like your code does. Can you attach te workbook?
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Valued Forum Contributor Excelenator's Avatar
    Join Date
    07-25-2006
    Location
    Wantagh, NY
    Posts
    333
    What is the purpose of this? Do you intend to declare a NUMBER as a variable? What purpose does this serve? This is not allowed by the compiler.
    Please Login or Register  to view this content.
    Change the number to a letter and then you may have some luck. Also, you don't need to SELECT cells to get their values. This is inefficient.
    ---------------------------------------------------
    ONLY APPLIES TO VBA RESPONSES WHERE APPROPRIATE
    To insert code into the VBE (Visual Basic Editor)
    1. Copy the code.
    2. Open workbook to paste code into.
    3. Right click any worksheet tab, select View Code
    4. VBE (Visual Basic Editor) opens to that sheets object
    5. You may change to another sheets object or the This Workbook object by double clicking it in the Project window
    6. In the blank space below the word "General" paste the copied code.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello sarahng86,

    The referencing problem is from using syntax like Sheet16.Range("B2").Seelct. Worksheet formulas allow you to designate a worksheet name this way, but it is a little more involved in VBA. The worksheet's name is actually a key value into the Worksheets Object Collection. Here is how your reference should be...
    Please Login or Register  to view this content.
    The Sheets Object Collection also includes Chart Sheets, while Worksheets does not. There are other problems, but we will take them one at a time.

    Sincerely,
    Leith Ross

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Sarah,

    Assuming Sheet4, Sheet6, and Sheet16 are code names rather than sheet names of your worksheets, that aspect of your code is fine.

    It took me a few minutes to prototype a workbook, but this worked for me:
    Please Login or Register  to view this content.
    See attached.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    10-28-2007
    Posts
    6

    thanks!

    thanks to all of you for helping =)
    yeps ive tried ur suggestions n it works =)

  7. #7
    Registered User
    Join Date
    10-28-2007
    Posts
    6

    thanks and need additional advice

    Hi,

    I applied shg's code

    just wondering if i can ammend it in this way to also populate another listbox as below - the 2nd listbox isn't populating - so not sure what's the problem


    Please Login or Register  to view this content.

+ 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