OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 855
- Office Version
- 365
- Platform
- Windows
Team Mr Excel
I hope that someone is willing to assist with my issue. This has really got me down.
In a workbook -- that I have spent A LOT of time on -- I get an intermittent error. Most times code works flawlessly, other times it crashes mid operation. The error really is intermittent! Here is what workbook does and where the issue crops up.
The "master" workbook (the one with the code) opens a "data" workbook and formats it. That works correctly.
Data in the "data" workbook includes rows for what are called centers. A center is a purchaser of product.
For each center my code creates a copy of a "template" workbook which becomes the "target" workbook. That works correctly.
Then, in the "data" workbook code hides rows that are not for the respective center being processed. That works too.
Code then clears the clipboard. That works correctly.
Code then makes a picture of the data in the "data" workbook by copying the range of data for the center being processed. No problem there.
The picture is pasted into the "target" workbook, into the cell specified by code. BUT during about 5% of iterations code crashes when doing the paste of the picture into the "target" workbook. Sometimes code actually processes all centers as expected. (There are 25 centers.)
I know that a snippit of code won't allow debugging but the offending code is the paste command shown below.
Any thoughts about what I might try to stop the intermittent behavior?
I hope that someone is willing to assist with my issue. This has really got me down.
In a workbook -- that I have spent A LOT of time on -- I get an intermittent error. Most times code works flawlessly, other times it crashes mid operation. The error really is intermittent! Here is what workbook does and where the issue crops up.
The "master" workbook (the one with the code) opens a "data" workbook and formats it. That works correctly.
Data in the "data" workbook includes rows for what are called centers. A center is a purchaser of product.
For each center my code creates a copy of a "template" workbook which becomes the "target" workbook. That works correctly.
Then, in the "data" workbook code hides rows that are not for the respective center being processed. That works too.
Code then clears the clipboard. That works correctly.
Code then makes a picture of the data in the "data" workbook by copying the range of data for the center being processed. No problem there.
The picture is pasted into the "target" workbook, into the cell specified by code. BUT during about 5% of iterations code crashes when doing the paste of the picture into the "target" workbook. Sometimes code actually processes all centers as expected. (There are 25 centers.)
I know that a snippit of code won't allow debugging but the offending code is the paste command shown below.
VBA Code:
' ----------------------------------------------------------
sStepID = "6.c. making picture of data for a center"
' ----------------------------------------------------------
' Update values in grand total line to include sum of visible rows
' (for the center being processed).
Application.Calculate
' Create a picture of the data for the center.
rAllRawData.Copy
' ---------------------------------------------------------------------
sStepID = "6.d. putting picture of data into center workbook"
' ---------------------------------------------------------------------
' Activate "target" workbook with one worksheet.
wbSSCD_CS_IRAA.Activate
' Activate 1st (anchor) cell in the header range as target for paste.
Range("AnchorCell").Activate
' Paste picture into the workbook. Crash about 5% of the time.
Set oPicture = ActiveSheet.Pictures.Paste
' Make the picture opaque.
With oPicture.ShapeRange.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
.Solid
End With
Any thoughts about what I might try to stop the intermittent behavior?