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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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.
 
Upvote 0
Pause Application for One Second

VBA Code:
Application.Wait (Now() + TimeValue("00:00:01"))
 
Upvote 0
Solution
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!
 
Upvote 0
When you get it working I would be interested in seeing your final project / workbook.
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,176
Members
448,554
Latest member
Gleisner2

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
Back
Top