+ Reply to Thread
Results 1 to 6 of 6

Help with buggy code, copies shape in one sheet and pastes to anchor cell in other sheet

  1. #1
    Registered User
    Join Date
    01-06-2015
    Location
    Pacific Northwest
    MS-Off Ver
    2010
    Posts
    38

    Help with buggy code, copies shape in one sheet and pastes to anchor cell in other sheet

    Hello,
    I have attached an example workbook that will fail the task if the buttons 1 through 3 are randomly and quickly clicked on repeatedly. This does simulate the problem that I am having. On the full workbook the picture delete and paste works only at about a 50% rate and seems to have a very hard time recovering. The attached workbook needs a lot of repeated random clicking of the 3 buttons to fail only 2-5% of the time but the failure is the same. The code that deletes old pics first works but the failure comes in past opperation.
    PicError.JPGPicError2.JPG
    Trying to attach the workbook. Thanks, Bud

    PictureCopyPasteExample.xlsm

  2. #2
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Help with buggy code, copies shape in one sheet and pastes to anchor cell in other she

    There are two approaches:
    1. ignore button presses until the actions are complete for the one in progress. The normal way to do this is to disable and enable buttons at the start and end of the routine. Or set a flag at the start and end and test it at the start to see if a routine is in progress
    2. stack up the clicks and play them all in sequence - a lot more difficult to achieve in Excel - actually might not be possible in native Excel


    Please Login or Register  to view this content.


    click on the * Add Reputation if this was useful or entertaining.

  3. #3
    Registered User
    Join Date
    01-06-2015
    Location
    Pacific Northwest
    MS-Off Ver
    2010
    Posts
    38

    Re: Help with buggy code, copies shape in one sheet and pastes to anchor cell in other she

    Quote Originally Posted by tony h View Post
    There are two approaches:
    1. ignore button presses until the actions are complete for the one in progress. The normal way to do this is to disable and enable buttons at the start and end of the routine. Or set a flag at the start and end and test it at the start to see if a routine is in progress
    2. stack up the clicks and play them all in sequence - a lot more difficult to achieve in Excel - actually might not be possible in native Excel


    Please Login or Register  to view this content.
    Thanks Tony H,
    I'll give it a try. Just to clarify that the repeated pushing of the buttons on the example workbook only simulates what is going on in my full workbook. In that workbook there will be at minimum 30 plus seconds to several minutes between button clicks and this code request and still it will fail. Now I'm wondering if something else is happening in the background that I can't see.
    I'll give it a go though and if the buttons are inactive then that may give me a clue as well.

    Thanks,
    Bud

  4. #4
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Help with buggy code, copies shape in one sheet and pastes to anchor cell in other she

    you might want to set some sort of flag on the worksheet to see if IsInUse is set or not. Eg colour a cell red when true and green when you set IsInUse to false.

    PS I couldn't get your demo to error. So I set up a random loop to go through a thousand clicks and it still didn't error - the pictures didn't change as screen repainting lagged behind but it didn't error.

  5. #5
    Registered User
    Join Date
    01-06-2015
    Location
    Pacific Northwest
    MS-Off Ver
    2010
    Posts
    38

    Re: Help with buggy code, copies shape in one sheet and pastes to anchor cell in other she

    Quote Originally Posted by tony h View Post
    you might want to set some sort of flag on the worksheet to see if IsInUse is set or not. Eg colour a cell red when true and green when you set IsInUse to false.

    PS I couldn't get your demo to error. So I set up a random loop to go through a thousand clicks and it still didn't error - the pictures didn't change as screen repainting lagged behind but it didn't error.
    Interesting that you couldn't get the workbook to fail at all. I have a lot of memory and CPU speed in my laptop and I can get it to fail easily. Its one thing if the screen repaint is not keeping up but to not fail and give you a code is another.
    Again makes me wonder if something else is going on. I like the cell flagging for a visual reference so I'll try that too.

  6. #6
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Help with buggy code, copies shape in one sheet and pastes to anchor cell in other she

    And just on the subject of good practice ...
    It is good practice to declare all variables before you use them this is done with DIM statements. These should also define the type as definitively as possible.
    examples are:
    Dim myString as string
    Dim myInt as integer
    dim rng as range
    dim wks as worksheet

    And Excel will ensure that you have declared everything if you make the first line of every module OPTION EXPLICIT

    There are three real benefits to this:
    1. it protects you against accidentally missplellin something
    2. it protects you against misusing something
    3. the editor will give you more help on using objects that you declare

+ 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. Need to create a sales planner that copies and pastes data from one sheet to another.
    By gjmathews in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-23-2015, 05:02 PM
  2. VBA Code copies and pastes the formulas? I only need the values.
    By tysonbly in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-14-2015, 11:20 AM
  3. Macro that copies data from one sheet and pastes it to another x columns to the right
    By Stevebarnes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-30-2013, 12:26 PM
  4. [SOLVED] Automating a macro that copies and pastes data and pastes 2 rows under the previous one.
    By thebank in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2012, 05:02 PM
  5. I have a script in where it copies a sheet's data, and pastes it, but over pastes...
    By Cyberpawz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-24-2012, 02:20 AM
  6. Replies: 0
    Last Post: 04-21-2010, 06:14 AM
  7. Cell as reference anchor to another sheet
    By michael.g in forum Excel General
    Replies: 17
    Last Post: 10-29-2009, 04:29 PM

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