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:
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
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
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