+ Reply to Thread
Results 1 to 2 of 2

Error "Object variable or With block variable not set" returning worksheet to function

  1. #1
    Registered User
    Join Date
    09-06-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    1

    Error "Object variable or With block variable not set" returning worksheet to function

    Hi guys!

    I would like to create a function that returns a named worksheet to the caller. I have tried very many ways to do this with various syntax. All compile, but all return the same error at runtime:

    "Object variable or With block variable not set"

    Here's the calling code:

    Please Login or Register  to view this content.
    And here's the function:

    Please Login or Register  to view this content.
    I just can't understand this. There must be a worksheet object by this name. I can see it with my own eyes, and I've just seen the code return the name of it in a message box... but when I try to return it from my function, it errs.

    I'm not a VBA developer. I'm a .NET developer trying to muddle along. Am I doing something really silly here? A big "thank you" to anybody who can help.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,453

    Re: Error "Object variable or With block variable not set" returning worksheet to function

    Try using: Set FindWorksheet = ActiveWorkbook.Sheets(worksheetName)


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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