Inserting copied row code causes Excel to hang (swirly blue circle)

xlchris

New Member
Joined
Jul 18, 2014
Messages
1
Hello one and all,

I've inherited a Macro enabled spreadsheet I'm trying to make work on Excel 2013, it works OK on Excel 2007 and below.

Problem:
Manually selecting, copying and inserting a row works OK; however, when running the code below on later versions of Office it causes Excel to stop working for want of a better word, it doesn't crash, and some buttons still respond but the busy icon (on Windows 8 its a blue swirly circle) is active, high CPU usage and you're unable to cleanly close Excel (you have to use PSKill)

Background:
It's a data entry form. There is a drop down box in column C (3) which includes a + (plus) symbol, if you click this it fires off the below code to copy the existing row and insert it below.

This is the code behind the Sheet2 Worksheet - Change event:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect Password:="IwishIknewExcel"


On Error GoTo errHnd


If Target.Cells.Count > 1 Then Exit Sub


'Determine if the changed cell is in Column 3 and is = "+"
     If Target = "+" Then
'Disable events so code doesn't fire again when row is inserted
     Application.EnableEvents = False
    Copy & Insert changed Row, Clear dotted lines
      Target.EntireRow.Copy
      Range("A" & Target.Row + 1).Insert Shift:=xlDown
      Application.CutCopyMode = False
      r = ActiveCell.Row
      Cells(r, 5).ClearContents
      Cells(r, 6).ClearContents
      Cells(r, 7).ClearContents
      Cells(r, 8).ClearContents
      Cells(r, 9).ClearContents
      Cells(r, 10).ClearContents
      Cells(r, 11).ClearContents
      On Error GoTo 0
   End If
  
errHnd:
'Re-enable event
 Application.EnableEvents = True
 


End Sub
I'm not a programmer, I've scoured these forums and others and tried a variety of different VBA code for inserting the rows, all of which end up with the same result. I think its something related to inserting the copied data, inserting a blank row on its own works just fine, but when you programatically insert a copied row the problem occurs.

There are excel formulas in the copied fields so I deleted all those too as a test but it still crashes. I even created a brand new spreadsheet and copied across the forms and recreated the modules but it does exactly the same.

Am stumped!

Thank you
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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