Macro keeps giving debug error

kingspur06

Board Regular
Joined
Apr 24, 2007
Messages
50
I have several tabs which I need to copy paste into a single tab to allow a pivot table to be created on the consolidated information.
I created it by recording it but I constantly get a debug error "Code Execution has been interrupted"
It also doesn't seem to stop at the same place each time.

My macro looks like this

VBA Code:
Sub ConsolData()
'
' ConsolData Macro
'
' Keyboard Shortcut: Ctrl+a
'
    Sheets("UK").Select
    Columns("A:BF").Select
    Selection.Copy
    Sheets("Consolidated Data").Select
    Range("A1").Select
    ActiveSheet.Paste
    Range("A2000").Select
    
    Sheets("Spain").Select
    Range("A2:BF1000").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Consolidated Data").Select
    ActiveSheet.Paste
    Range("A2999").Select
    
    Sheets("Europe").Select
    Range("A2:BF1000").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Consolidated Data").Select
    ActiveSheet.Paste
    Range("A3998").Select
    
    Sheets("USA").Select
    Range("A2:BF1000").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Consolidated Data").Select
    ActiveSheet.Paste
    Range("A4997").Select
    
    Sheets("Archive 22-23").Select
    Range("A2:BF1150").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Consolidated Data").Select
    ActiveSheet.Paste
    
    Sheets("Summary").Select
End Sub


I suspect the issue may be being caused by another macro that I have running which highlights cells whenever a constant value is entered after you have entered that sheet. When I step through my original macro, it always runs through the 2nd macro when going into each sheet.

The 2nd macro is

VBA Code:
Option Explicit
Private Sub Worksheet_Activate()
Dim cell As Range
On Error Resume Next
For Each cell In ActiveSheet.Range("o2:aa2000").SpecialCells(xlCellTypeConstants)
cell.Interior.ColorIndex = 17
Next
End Sub

Does anyone have any suggestions, either how to consolidate my sheets into one sheet more elegantly, or how to prevent the bugging?
many thanks
Mark
 
The message "Code Execution has been interrupted" generally means that you have hit Break forcing an interruption to execution. I have seen this happen without hitting break but never been able to reproduce it. There may be some buggy interaction with other processes. It is very strange that you get this repeatedly.

I agree with HaHoBe that you should try a reboot.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi Mark,

what came to my mind is how you have assigned the shortcut for the macro: if you have done so using the Macro Options window alone (which would make the macro available in every open workbook and would mean to include the name of the workbook in order make the code available only in one workbook) or via VBA in ThisWorkbook like

VBA Code:
Private Sub Workbook_Open()
  Application.OnKey "^{A}", "ConsolData"
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
  Application.OnKey "^{A}", ""
End Sub

Private Sub Workbook_Activate()
  Application.OnKey "^{A}", "ConsolData"
End Sub

Private Sub Workbook_Deactivate()
  Application.OnKey "^{A}", ""
End Sub

On my system (Windows11, Excel2019 Professional) I was not able to assign the shortcut CTRL+a like indicated in your comment (command should select all cells in the sheet) but have assigned CTRL+SHIFT+a (or as shown above CTRL+A). I deactivated the shortcut on the Macro Options window and after switching workbooks the macro could only work in one workbook, the one holding the commands.

This certainly does not explain why you have faced the error - I'm sorry I can't offer a solution to avoid this for the future.

Ciao,
Holger
 
Upvote 0
Hi everyone - many thanks to you all for your responses. It is now working today. I don't know whether it was the full reboot that I did. I also noticed I had accidently pulled in references to an external source which I have now removed. Again not sure if that had anything to do with it.....but it all works great.
Thank you once again!!!
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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