+ Reply to Thread
Results 1 to 4 of 4

Script out of Range

  1. #1
    Forum Contributor
    Join Date
    04-09-2005
    Location
    Multan. Pakistan
    Posts
    129

    Script out of Range

    Dear Folks

    I have the following codes to generate a stock report in worksheet "CottonRegister" based on Worksheets "CottonPurchase" and "CottonIssue". It is working well in my PC, but when I copy theses worksheets to my PC at office at the same path i.e at Drive C:\ and run the Program it stops at line " Application.WorksheetFunction.SumIf(Workbooks("CottonPurchase").Worksheets("CottonPurchase").Range("d:d"), Cells(x, 1), Workbooks("CottonPurchase").Worksheets("CottonPurchase").Range("g:g"))" saying that Run Time Error 9 and script out of range.

    Please Login or Register  to view this content.
    Last edited by VBA Noob; 09-23-2007 at 06:28 AM.

  2. #2
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544
    Hi,

    Are all 3 files opened correctly at the beginning of your code ?

    Is there a particular reason why you store these files on the root drive C: , and is the file that contains this code also on C: ?

    Erik
    Just keep it simple !


    http://www.excelguide.eu
    In English as well as in Dutch

  3. #3
    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 Syed,

    You don't mention what the value of x is at the time of the error. Is it failing as soon as the loop starts or later on? Place a breakpoint at that line by placing the cursor next to the line and press F9. When the macro runs, you can then step through x, and see if fails at a particular value. If the code is failing as soon as the loop starts, check which sheets are active in each workbook at home, and at work. If the office copy is different, have the code activate the same sheets before the macro runs.

    Sincerely,
    Leith Ross

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Try adding the xls file extension when trying to refer to the workbook(s).

    Note this could easily be avoided if you created references to the workbooks when you open them.

    For example:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I would also warn you that you could run into problems due to unqualied references like this.
    Please Login or Register  to view this content.
    PS Oh, and you don't need to use Select.

+ 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