Hi All,
First post so please be gentle I've written the following macro to insert a row, copy some cells from another sheet and then paste them into the new row. The problem occurs when I use this macro more than once it crashes Excel 2003 out! Any help greatly appreciated:
### Code Begins ###
Option Explicit
Option Compare Text
Sub InsertRow()
Dim rFind As Long
On Error Resume Next
'Disables Sheet Protection
ActiveSheet.Unprotect
'Stop Updating of The Screen To Optimise Speed
Application.ScreenUpdating = False
'Prevent Prompting
Application.DisplayAlerts = False
'If rFind > 0 Then Rows(rFind + 1).Insert xlShiftDown
'Selects Entire Last Row
Sheets("Format Control").Select
Rows("3:3").Select
'Copies Entire Last Row
Selection.Copy
'Selects the Environment Information Sheet
Sheets("Environment Information").Select
rFind = Columns("A:A").Find(What:="0", After:=Range("A5"), LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Row
If rFind > 0 Then Rows(rFind + 1).Insert xlShiftDown
'Enable Prompting
Application.DisplayAlerts = False
'Update The Screen
Application.ScreenUpdating = True
'Enables Sheet Protection
'ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
ActiveCell.Offset(4, -3).Select
End Sub
### Code Ends ###
My knowledge of VBA is minimal to be honest but if anyone has any suggestions I would be very grateful.
*Edit* I've just had an error appear from 'Microsoft Visual Basic' stating 'Automation Error'. This doesn't seem to affect any other macros in this workbook and there are a few.
Thank you all for your time.
First post so please be gentle I've written the following macro to insert a row, copy some cells from another sheet and then paste them into the new row. The problem occurs when I use this macro more than once it crashes Excel 2003 out! Any help greatly appreciated:
### Code Begins ###
Option Explicit
Option Compare Text
Sub InsertRow()
Dim rFind As Long
On Error Resume Next
'Disables Sheet Protection
ActiveSheet.Unprotect
'Stop Updating of The Screen To Optimise Speed
Application.ScreenUpdating = False
'Prevent Prompting
Application.DisplayAlerts = False
'If rFind > 0 Then Rows(rFind + 1).Insert xlShiftDown
'Selects Entire Last Row
Sheets("Format Control").Select
Rows("3:3").Select
'Copies Entire Last Row
Selection.Copy
'Selects the Environment Information Sheet
Sheets("Environment Information").Select
rFind = Columns("A:A").Find(What:="0", After:=Range("A5"), LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Row
If rFind > 0 Then Rows(rFind + 1).Insert xlShiftDown
'Enable Prompting
Application.DisplayAlerts = False
'Update The Screen
Application.ScreenUpdating = True
'Enables Sheet Protection
'ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
ActiveCell.Offset(4, -3).Select
End Sub
### Code Ends ###
My knowledge of VBA is minimal to be honest but if anyone has any suggestions I would be very grateful.
*Edit* I've just had an error appear from 'Microsoft Visual Basic' stating 'Automation Error'. This doesn't seem to affect any other macros in this workbook and there are a few.
Thank you all for your time.
Last edited: