+ Reply to Thread
Results 1 to 10 of 10

Help with Reslving a VBA Code Execution Error

  1. #1
    Registered User
    Join Date
    08-06-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    7

    Question Help with Reslving a VBA Code Execution Error

    Hello,

    I've written a VBA macro that allows me to perform an automatic data retrieval on daily basis from a PI Server using Excel's add-on "PI DataLink". Within my spreadsheet, certain columns get populated with arrays from PI DataLink while others are formulas that simply need to be copied down daily as new PI data gets retrieved into the spreadsheet. However, when I execute the code, I receive the following error: "Application-defined or object-defined error" after the code activates my "Prod Allocation" worksheet and attempts to select a certain row. The error occurs at the following command: Workbooks("Voidage Replacement & Production Allocation.xlsm").Sheets("Prod Allocation").Range(Cells(i - 2, 8), Cells(i - 2, 122)).Select

    I've checked the code and verified the worksheet name dozens of times to ensure there is not a spelling error, and I'm unable to figure out why the code fails on selecting a certain line. Could you please help me resolve this issue? The code is shown in full below. Not sure if this is relevant, but all coding was done in Excel 2010.

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Please Login or Register  to view this content.
    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Last edited by yegor2000; 09-22-2014 at 03:00 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Help with Reslving a VBA Code Execution Error

    Unfortunately your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    08-06-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Help with Reslving a VBA Code Execution Error

    My apologies, just made the appropriate changes.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Help with Reslving a VBA Code Execution Error

    Does your error appear right at the first iteration? Or is i already a higher number?
    Odd nothing seems wrong, and it should not be a typo on sheet name, as you have activated that sheet already by the time you go to select.

    Question, is your "Prod Allocation" sheet hidden? That allows the activate command I'm pretty sure, but you can't select .... it would generate that error.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  5. #5
    Registered User
    Join Date
    08-06-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Help with Reslving a VBA Code Execution Error

    The code failure occurs at higher "i" iterations, and the sheet is not hidden.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Help with Reslving a VBA Code Execution Error

    Where is this code located?
    If posting code please use code tags, see here.

  7. #7
    Registered User
    Join Date
    08-06-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Help with Reslving a VBA Code Execution Error

    I'm not sure I understand the question. The code is located in a sheet under Microsoft Excel Objects and is assigned to a macro that runs it. I can attach the entire Excel file, so you can take a look at the whole macro, if that would be helpful....

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Help with Reslving a VBA Code Execution Error

    Yegor, it should be in a module, not sheet.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Help with Reslving a VBA Code Execution Error

    You need to make sure every instance of Cells and Range has a worksheet reference.

    For example this,
    Please Login or Register  to view this content.
    should be something like this.
    Please Login or Register  to view this content.
    If you don't have worksheet references then the code is going to error as VBA will be interpreting Cells/Range to be referring to either the active worksheet, or, if the code is in a sheet module, the sheet whose module the code is in.

  10. #10
    Registered User
    Join Date
    08-06-2012
    Location
    Houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Help with Reslving a VBA Code Execution Error

    Arkadi, your suggestion did the trick, so the code is now working just fine! Thank you!

    Norie, I haven't tried your recommendation as the one just above yours seemed to resolve the problem, but I'll give yours a try as well! Many thanks for all the help!

+ 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] VBA Code Error Upon Execution
    By MacroMan87 in forum PowerPoint Programing
    Replies: 4
    Last Post: 09-21-2013, 01:28 AM
  2. Automation Error At Odd Spot in Code Execution
    By Jenn68 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 05-02-2012, 11:50 AM
  3. Code execution has been interrupted error
    By vpnvipin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2012, 04:35 AM
  4. Error: Code Execution Has Been Interrupted
    By Xrull in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2010, 07:32 AM
  5. error: Code Execution has been interrupted
    By Joshua Fredrickson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-23-2005, 11:50 AM

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