+ Reply to Thread
Results 1 to 4 of 4

Error 91 - Object Variable Not Set error with Global Variable

  1. #1
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Error 91 - Object Variable Not Set error with Global Variable

    Hi,

    Not a VBA developer but I am writing private sub within a module that uses two workbook variables which are declared globally. The two variables are MyWbk and TempWbk - both are set in other subs...

    Please Login or Register  to view this content.
    It is this final line that brings up the 91 "Object Variable not set" error - but the object is Set in an earlier sub...

    if i change the Frsthdrtxt in the Find statement to "*" - the statement executes....if i change it to a hard coded text string such as "MYTEXT" - i get the 91 error again....

    The purpose of the above statement is to grab the header from A1 in the Temp workbook, assign it to the variable Frsthdrtxt and find that in My Workbook, i thought it would be simple, but i'm getting stuck...

    I've tried setting MyWbk and TempWbk to Nothing in the Sub and then putting in the Set statements within the Private Sub in which this line is executing, but that hasn't worked....any help is greatly appreciated!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Sounds like the Find hasn't found anything.
    If posting code please use code tags, see here.

  3. #3
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Error 91 - Object Variable Not Set error with Global Variable

    The error means that your search text is not found. Many reasons why that may be so - perhaps the code is searching formulas rather than values or vv. Better to provide all options for the Find method and then verify that the search data is correct, and the search location as well.

  4. #4
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Re: Error 91 - Object Variable Not Set error with Global Variable

    Wood for the trees!

    I'm a VBA novice really - so immediately assumed that my syntax or declarations were some how wrong.

    But you are right! its actually the source data - there was a difference between the header values where i assumed they were the seem - so the find didn't work....!

    Thanks so much....feeling a bit stupid but at least it is fixed!

+ 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] Excel VBA error code 91: Object variable or with block variable not set
    By wilnexpc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-24-2013, 11:46 AM
  2. Replies: 0
    Last Post: 04-16-2013, 07:15 AM
  3. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  4. Error 91 object variable block variable not set when importing a CVS file
    By ReportBuilder2011 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2011, 11:48 AM
  5. Find Method error: -Object variable with block set variable not set
    By bambino_32 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 06-02-2010, 01:18 AM

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