Crashing Macro

JamesRo

New Member
Joined
Jun 30, 2022
Messages
26
Office Version
  1. 2021
Platform
  1. Windows
Hi.
Wondering if anybody can shine any light...

Win 11 Pro
Office MHAB 2021

Have a problem with a macro that was previously working okay but now when I run it, Excel hangs and eventually crashes.
Nothing in the macro has changed and I can run it in a different sheet and works fine.
The workbook has connections to SQL server database and is fairly complicated to paste here but the macro is below.
I have stepped through the code and seems to get to the "copy I column comments" ActiveSheet.Paste line then hangs.
I know this is vague but is there anything to check?
As I said, the macro was working fine until a couple of weeks ago, any reason the paste might be failing?

TIA


VBA Code:
Sub New_Week()
'
    If MsgBox("Are you sure?" & vbNewLine & "This action cannot be undone!", vbYesNo) = vbNo Then Exit Sub
'
    ActiveSheet.Unprotect

' copy comments area WEEK 1

' Mon
    Range("E58:H58").Select
    Selection.Copy
    Range("E2:H2").Select
    ActiveSheet.Paste
    
'Tue
    Range("E69:H69").Select
    Selection.Copy
    Range("E13:H13").Select
    ActiveSheet.Paste
    
'Wed
    Range("E81:H81").Select
    Selection.Copy
    Range("E25:H25").Select
    ActiveSheet.Paste
    
'Thu
    Range("E93:H93").Select
    Selection.Copy
    Range("E37:H37").Select
    ActiveSheet.Paste
    
'Fri
    Range("E104:H104").Select
    Selection.Copy
    Range("E48:H48").Select
    ActiveSheet.Paste
    
    ' copy comments area WEEK 2
'Mon
    Range("E114:H114").Select
    Selection.Copy
    Range("E58:H58").Select
    ActiveSheet.Paste

'Tue
    Range("E125:H125").Select
    Selection.Copy
    Range("E69:H69").Select
    ActiveSheet.Paste

'Wed
    Range("E137:H137").Select
    Selection.Copy
    Range("E81:H81").Select
    ActiveSheet.Paste

'Thu
    Range("E149:H149").Select
    Selection.Copy
    Range("E93:H93").Select
    ActiveSheet.Paste

'Fri
    Range("E160:H160").Select
    Selection.Copy
    Range("E104:H104").Select
    ActiveSheet.Paste
    
    ' copy comments area WEEK 3
'Mon
    Range("E170:H170").Select
    Selection.Cut
    Range("E114:H114").Select
    ActiveSheet.Paste

'Tue
    Range("E181:H181").Select
    Selection.Cut
    Range("E125:H125").Select
    ActiveSheet.Paste

'Wed
    Range("E193:H193").Select
    Selection.Cut
    Range("E137:H137").Select
    ActiveSheet.Paste

'Thu
    Range("E205:H205").Select
    Selection.Cut
    Range("E149:H149").Select
    ActiveSheet.Paste

'Fri
    Range("E216:H216").Select
    Selection.Cut
    Range("E160:H160").Select
    ActiveSheet.Paste
    
' unprotect editable cells

    Range("E170:H170").Locked = False
    Range("I170:I179").Locked = False
    
    Range("E181:H181").Locked = False
    Range("I181:I191").Locked = False
    
    Range("E193:H193").Locked = False
    Range("I193:I203").Locked = False
    
    Range("E205:H205").Locked = False
    Range("I205:I214").Locked = False
    
    Range("E216:H216").Locked = False
    Range("I216:I223").Locked = False
   
    
' copy I column comments
    Range("I58:I223").Select
    Selection.Copy
    Range("I2:I167").Select
    ActiveSheet.Paste
    
    Range("I170:I223").Select
    Selection.ClearContents
   
' copy VM quantities
'W1 Mon
    Range("P63").Select
    Selection.Copy
    Range("P7").Select
    ActiveSheet.Paste
'W1 Tue
    Range("P74").Select
    Selection.Copy
    Range("P18").Select
    ActiveSheet.Paste
'W1 Wed
    Range("P86").Select
    Selection.Copy
    Range("P30").Select
    ActiveSheet.Paste
'W1 Thu
    Range("P98").Select
    Selection.Copy
    Range("P42").Select
    ActiveSheet.Paste
'W1 Fri
    Range("P109").Select
    Selection.Copy
    Range("P53").Select
    ActiveSheet.Paste
    
'W2 Mon
    Range("P119").Select
    Selection.Copy
    Range("P63").Select
    ActiveSheet.Paste
'W2 Tue
    Range("P130").Select
    Selection.Copy
    Range("P74").Select
    ActiveSheet.Paste
'W2 Wed
    Range("P142").Select
    Selection.Copy
    Range("P86").Select
    ActiveSheet.Paste
'W2 Thu
    Range("P154").Select
    Selection.Copy
    Range("P98").Select
    ActiveSheet.Paste
'W2 Fri
    Range("P165").Select
    Selection.Copy
    Range("P109").Select
    ActiveSheet.Paste
    
'W3 Mon
    Range("P175").Select
    Selection.Copy
    Range("P119").Select
    ActiveSheet.Paste
'W3 Tue
    Range("P186").Select
    Selection.Copy
    Range("P130").Select
    ActiveSheet.Paste
'W3 Wed
    Range("P198").Select
    Selection.Copy
    Range("P142").Select
    ActiveSheet.Paste
'W3 Thu
    Range("P210").Select
    Selection.Copy
    Range("P154").Select
    ActiveSheet.Paste
'W3 Fri
    Range("P221").Select
    Selection.Copy
    Range("P165").Select
    ActiveSheet.Paste
   
' add comments

   ' Range("E158:I207").Select
   ' Selection.ClearContents
    'Range("E128").Select
    'ActiveCell.FormulaR1C1 = "Mxxx"
    'Range("E128").Select
    'Selection.Copy
   
    'Range("E136").Select
    'ActiveSheet.Paste
   
    'Range("E145").Select
    'ActiveSheet.Paste
   
    'Range("E153").Select
    'ActiveSheet.Paste
   
    'Range("E161").Select
    'ActiveSheet.Paste
    
' zero VM for new week

    Range("P175").Select
    ActiveCell.FormulaR1C1 = "0"
    Range("P186").Select
    ActiveCell.FormulaR1C1 = "0"
    Range("P198").Select
    ActiveCell.FormulaR1C1 = "0"
    Range("P210").Select
    ActiveCell.FormulaR1C1 = "0"
    Range("P221").Select
    ActiveCell.FormulaR1C1 = "0"
    
' set cell formatting for new week
    Range("I167").Select
    Selection.Copy
    
    Range("E170:I170,I171:I179,E181:I181,I182:I191,E193:I193,I194:I203,E205:I205,I206:I214,E216:I216,I217:I223").Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False

    
    
    Range("A2").Select
        
    ActiveSheet.Protect
    
    End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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