+ Reply to Thread
Results 1 to 2 of 2

Workbook not defined as Global error after finishing a loop

  1. #1
    Registered User
    Join Date
    10-26-2017
    Location
    Philippines
    MS-Off Ver
    Office 365
    Posts
    5

    Workbook not defined as Global error after finishing a loop

    I created an automation of online survey creation that will create survey based on available data on a certain cell but once the loop ends an error points to 'If ThisWorkbook.Sheets("Sheet1").Range("B" & count) <> "" Then' as this was not defined as global.

    Below is my code;

    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Workbook not defined as Global error after finishing a loop

    I don't recognize that error--are you sure you copied the error text correctly?--and it doesn't seem to make sense in the context of your code. This line of code is inside the loop so I don't understand what you mean when you say this happens once the loop ends.

    But you have a couple of other problems you should fix. Fixing these may resolve the other issue.

    You have a logical redundancy. You have a Do Until Status <> "", which means if you are going into the loop, Status = "". But the first statement is to test If Status = "". If you reach this If statement, it will always be true. This does not cause an error but this If statement is not necessary.

    You have a loop that exits when Status <> "", but you never update Status inside the loop. If you enter the loop the first time, you will never exit. My guess is that count is going to a high value which is causing your error.

    You are assigning Range("C" & count).Value to the value of variable Stat but variable Stat is never assigned a value. It will always be null.

    You have declarations like
    Please Login or Register  to view this content.
    I suspect you are not clear on the syntax of a Dim statement. Each variable in a Dim statement must have a data type, or the data type will default to Variant. In the first statement, for example, Status, Stat, ttle, will all be type Variant. Variable link will be String. repeat will be an Integer but count will be Variant.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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. application defined or object defined error while opening workbook
    By Awni in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-28-2016, 05:40 AM
  2. [SOLVED] Workbook Open Event Application-defined or object-defined error
    By dmw2014 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-29-2014, 10:28 AM
  3. Each Loop says Object or application defined error
    By mohdwasim41 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-07-2014, 05:50 AM
  4. Loop finishing too early!!
    By newbi004 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-16-2013, 01:23 PM
  5. Reopen workbook application-defined or object-defined error
    By Duzze5 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-02-2013, 11:21 AM
  6. [SOLVED] Loop not finishing
    By boomersooner5136 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-14-2012, 10:51 AM
  7. Resolved >>>For Loop not finishing.
    By Alan1981 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-25-2007, 09:03 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