Copy Paste fails randomly

MrNedF

New Member
Joined
Feb 22, 2018
Messages
4
I coded my own UPC code maker that builds a UPC on a sheet and then the code is copied and pasted in the target cell, but it randomly fails during the cut and paste. I know the code works as it runs flawlessly on my Surface running the same version of excel as my work laptop. I am thinking it might be a timing issue where the copy is not completing before the paste so there is nothing there to paste. I am thinking I might have to put in some sort of delay in after the copy to allow the computer to finish it before the call to paste. I guess I am wondering if a short loop after the copy might work or maybe I am missing another possible cause?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

MrNedF

New Member
Joined
Feb 22, 2018
Messages
4
I coded my own UPC code maker that builds a UPC on a sheet and then the code is copied and pasted in the target cell, but it randomly fails during the cut and paste. I know the code works as it runs flawlessly on my Surface running the same version of excel as my work laptop. I am thinking it might be a timing issue where the copy is not completing before the paste so there is nothing there to paste. I am thinking I might have to put in some sort of delay in after the copy to allow the computer to finish it before the call to paste. I guess I am wondering if a short loop after the copy might work or maybe I am missing another possible cause?
I should have mentioned the UPC code is copied and pasted as a picture not cells.
 

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
4,538
Pause Application for One Second

VBA Code:
Application.Wait (Now() + TimeValue("00:00:01"))
 
Solution

MrNedF

New Member
Joined
Feb 22, 2018
Messages
4
Pause Application for One Second

VBA Code:
Application.Wait (Now() + TimeValue("00:00:01"))
I forgot about Application.Wait. That did the trick. It does slow the code down considerably so I will expand from here and shorten the wait to fractions of a second until I get it fine tuned for both speed and successful execution. Thanks for your help!
 

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
4,538
When you get it working I would be interested in seeing your final project / workbook.
 

Forum statistics

Threads
1,176,201
Messages
5,901,890
Members
434,928
Latest member
mvbuccheri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top