+ Reply to Thread
Results 1 to 25 of 25

Subroutine is halted, but Excel acting strange - Cells don't appear selected...

  1. #1
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    What to know:
    -Excel 2010
    -Windows 7
    -Sheet is not protected
    -Restarting the program seems to fix it, until it eventually happens again.
    -Workbook attached. Button labeled: Click Here to Add Resource at row 50

    I run a macro that finds a 3 word string on a sheet, copies its row and the one below it, then inserts the copied cells over itself.
    Most of the time it works. But when it doesn't, I get the infamous:

    Run-Time Error: 1004
    Application-defined or object-defined error
    The obvious first assumption is that my .Find did not find what it was looking for. However, knowing that string is there (and this macro runs successfully most of the time), I'm not sure why I get this error.

    However, the real problem is after I END the macro. I can no longer see an outline around the cells I select, nor will the contents of the cell appear in the formula bar at the top. I can double click in a cell, and I can see my cursor and edit the contents, but I cannot see the selected cell.

    Two noticeable things:
    -The mouse is indicated by a hollow plus sign (same one you see when you hover over a highlighted area)
    -The mouse still turns into a hand when hovering over buttons.


    Here's the code:
    Please Login or Register  to view this content.
    I do have error handling, but I didn't include it to save space. When it works, it works great. When it errors, it never works again, and the sheet acts as mentioned previously.

    Any clues? What obvious thing am I missing...
    Attached Files Attached Files
    Last edited by paulcola; 05-04-2013 at 11:25 PM. Reason: attached workbook and updated code to reflect area of problem in workbook

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Hello paulcola,

    There may be many reasons why this code is failing. To get an answer to this problem more quickly, you should post a copy of your workbook.

    To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.

    File Manger Picture
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    @Leith: Done. Thanks!

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Try something like this. It may help to diagnose if you Dim all the variables as explicit types e.g.: Range

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Wow, I can't believe I forgot that. Yeah, I will correct the code to include Dim-ing and use Option Explicit.
    I do declare it as a Range in the called sub, but not initially which could cause a problem.

    Thanks for your feedback. Will keep testing and tweaking...

  6. #6
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Hmm, I'm wondering if it would be easier to use a named range, then select the rows based on the name, and not trying to Find a particular word in the column.

    In other words, name a cell NEW DESKTOP RESOURCE, then select the row where that cell is located.

    I chose to use .Find because the location of the cell will change. I'll see if that works...

  7. #7
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    oh, that works nicely! Maybe using a different subroutine altogether, I won't have this issue.
    I simply took out the range object I was defining, and instead named a cell in my spreadsheet, then referenced that cell to get the row #
    It's a much simpler, more efficient method.

    New code:
    Please Login or Register  to view this content.
    Crossing my fingers this continues to work well. Will test and close this thread if so.

  8. #8
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Well the code is more efficient, but the original issue still appears. It's hard to duplicate. When I Step Into the procedure and watch it run line by line, I can't duplicate the issue. When I click the macro, it happens, though rarely.

    I wonder if it's the subroutine I'm calling that's causing the problem. Here are both:

    Macro code:
    Please Login or Register  to view this content.
    insertNewRow subroutine...
    Please Login or Register  to view this content.
    I wonder if the code is running so quickly, that there is not enough time for Excel to perform one of these steps before going to the next.
    Puzzling...

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Hello paulcola,

    Perhaps now you'll consider my earlier request in Post #2.

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Hello paulcola,

    Perhaps now you'll consider my earlier request in Post #2.

  11. #11
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    @Leith: I wish I knew what you were referring to : (

    I attached as asked... is it not visible to you?

    It's in the original post.

    The code has been updated since that version however... I shall attach a new version momentarily

  12. #12
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Here is the updated version. Please ignore the attachment in my first post.

    Thanks!
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    I did remove one line from the latest version to help with troubleshooting:

    Please Login or Register  to view this content.
    Don't know if it makes a difference until the error comes back. I removed it thinking that excel may not like inserting copied cells, then immediately activating a cell (maybe excel needs more time after it insert cells? I'm reaching...)

  14. #14
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Problem still exists, regardless of the .Activate statement.

    I'm thinking
    Please Login or Register  to view this content.
    is the culprit. Wonder if there's a better way to do this...
    Last edited by paulcola; 05-05-2013 at 01:42 AM. Reason: code edit

  15. #15
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Hello paulcola,

    Thanks for posting the workbook. It opened as a 95-2003 format. Is this being used on OS versions earlier than 2007 only?

  16. #16
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Oh really? I didn't know that. I use it in 2010, and I believe that nothing earlier than 2007 is opening it (pretty sure it's only opened in ver 2010 though).

    I wonder how that happened...

  17. #17
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    I thought the xlsm format could only be opened in 2007 or later

  18. #18
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Hello paulcola,

    I was curious if this program was being or going to be run on more than one computer. Usually a workbook that will be used by more than one user will be saved in an earlier version for backward compatibility.

    Do you need the workbook saved in this earlier format?

  19. #19
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Quote Originally Posted by paulcola View Post
    Problem still exists, regardless of the .Activate statement.

    I'm thinking
    Please Login or Register  to view this content.
    is the culprit. Wonder if there's a better way to do this...
    Please Login or Register  to view this content.
    I couldn't get it to error. Tried 150 new inserts.

    When it does error for you, what is the value of newResourceRow?

  20. #20
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Thank you AlphaFrog. That's a lot of time you spent there, I appreciate that. I was just able to make it happen again - unfortunately, it's quite random. I'll let it sit a while, run the macro, and it happens. Next time, it doesn't.

    That's an excellent point Leith. I won't know until Monday. I don't want to save it as an earlier version, and would rather not. I need to find that out.

    The last time I got it to fail, Excel actually crashed. I'm now wondering if you're on to something Leith. There might be compatibility issues going on here. The code I've posted is not enough to make excel croak so easily.

    EDIT: In answer to your question, yes, many other computers (not shared, but saved on other PCs quite a bit)
    Last edited by paulcola; 05-05-2013 at 01:59 AM.

  21. #21
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Deleted repost.

  22. #22
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Quote Originally Posted by paulcola View Post
    Thank you AlphaFrog. That's a lot of time you spent there, I appreciate that. I was just able to make it happen again - unfortunately, it's quite random. I'll let it sit a while, run the macro, and it happens. Next time, it doesn't.
    I spent about 5 minutes on it.

    When it does error, look at the newResourceRow value within the code (before you OK the message) and make sure it's not zero for some yet unknown reason.

  23. #23
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Good advice. I will!

    Wait, just errored. newResourceRow is 93, which was the correct row at the time.

    When it's in that mode (where I can't seem to select cells), and I step into the code, I notice the last line it reads before it errors out is
    Please Login or Register  to view this content.
    That may not be saying much though. I think the spreadsheet is just stuck in some weird "I've selected something" mode, and it won't allow copying, pasting, etc. Or, as Leith is intimating, there's a possible compatibility issue going on.

    Jeez! I may have to setup some arrays or something to track every variable at every moment to see where it goes wrong.
    Last edited by paulcola; 05-05-2013 at 02:15 AM. Reason: Errored again, added info

  24. #24
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    Maybe one of you can test this:

    I've been able to duplicate the issue three times by zooming way out of the spreadsheet, then clicking a button.
    Using the zoom bar at the bottom right, I zoomed out to 30%, then clicked on CLICK HERE TO ADD RESOURCE under Telephony.

    UPDATE: I can duplicate it every time with zooming!
    UPDATE 2: I am able to pinpoint where it fails. Right after zooming out, then executing this line:
    Please Login or Register  to view this content.
    The variables are correct, nothing is null or zero. But it doesn't like that line after zooming out for some reason. : S
    Last edited by paulcola; 05-05-2013 at 02:38 AM. Reason: oops, wrong code. Reposted.

  25. #25
    Registered User
    Join Date
    03-31-2013
    Location
    Oregon
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Subroutine is halted, but Excel acting strange - Cells don't appear selected...

    After more troubleshooting today, I'm hoping I've solved this. Perhaps when you read this, one or both of you could test this with the file that you've already downloaded? If you have time, that is.

    1. I can duplicate the issue every time when I zoom in and out, then click on a macro. This calls the ErrorHandler event and a message appears. After that, you cannot select cells on the sheet.

    2. I cannot duplicate the issue after I deleted several hidden sheets. I can now zoom in and out, click the macro as much as I want, and have no problems.

    If I can get confirmation from someone else that they too can duplicate the two steps above, I'll consider this resolved.

    Thank you for your time!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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