Forum Discussion
V-GEe7
Aug 10, 2022Brass Contributor
Macro working only on debugging mode
Hi The Macro Runs on debugging mode but does not run normally where it either breaks at a different step everytime or runs smoothly but doesn't paste the graph shape and images in the compare sh...
- Sep 30, 2022
V-GEe7 Sometimes, the application cannot keep up with the code. DoEvents gives it a moment to catch up.
HansVogelaar
Aug 11, 2022MVP
It appears to be a timing problem. In the version below, I inserted a DoEvents line, Does it work for you?
Sub CompareButton()
Dim var As Integer
Sheets("Input").Select
ActiveSheet.ChartObjects("TopGraph").Copy
Sheets("workbench").Select
Range("C3").Select
ActiveSheet.Pictures.Paste.Select
Selection.Name = "GroupGraph"
Sheets("Input").Select
Range("Table2[ITM]").Copy
Sheets("Picture Query").Select
Range("B3").PasteSpecial xlPasteValues
ActiveSheet.Shapes.Range(Array("_P1", "_P2", "_P3", "_P4", "_P5", "_P6", "_P7", "_P8", "_P9", "_P10", "_P11", "_P12", "_P13", "_P14", "_P15", "_P16", "_P17", "_P18", "_P19", "_P20")).Select
Selection.Copy
DoEvents
Sheets("workbench").Select
Range("M2").Select
ActiveSheet.PasteSpecial Format:="Picture (Enhanced Metafile)", Link:=False, DisplayAsIcon:=False
Application.CutCopyMode = False
Selection.Name = "GroupPics"
ActiveSheet.Shapes.Range(Array("GroupPics", "GroupGraph", "_BG")).Select
Selection.Copy
Sheets("Comparison").Select
var = Range("B1").Value
Range("A2").Offset((var) * 26, 0).Select
ActiveSheet.Paste
ActiveCell.Value = var + 1
Range("A2").Select
Sheets("workbench").Select
ActiveSheet.Shapes.SelectAll
Selection.ShapeRange.Delete
Sheets("Input").Select
ActiveSheet.Shapes("_BG").Visible = True
ActiveSheet.Shapes("_BG").Copy
Sheets("workbench").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Picture Query").Select
Range("A2").Select
Sheets("Input").Select
ActiveSheet.Shapes("_BG").Visible = False
Range("A1").Select
End SubV-GEe7
Sep 29, 2022Brass Contributor
It seems to be working now though,
Thank you so much for your response.
Could you also help me understand why that helps?
Thanks in advance,
V
Thank you so much for your response.
Could you also help me understand why that helps?
Thanks in advance,
V
- HansVogelaarSep 30, 2022MVP
V-GEe7 Sometimes, the application cannot keep up with the code. DoEvents gives it a moment to catch up.