Hi there,
I have a macro (code below) that is assigned to a button in an Excel 2010 Macro Enabled Template (.xlsm). I push the button and it copies a pre-formatted row from one worksheet to another and pastes it beneath a row with a specified value in a column.
It works perfectly as long as I don't delete a row and then want to use this button to copy\insert a pre-formatted row again. If I do I am presented with the following error box upon execution:
This code works fantastic in Excel 2003 but we are about to migrate to Office 2010 (the error being in Execl 2010) and I really need the skills of some of the fantastic members on here to help me out.
Thank you for your time and any help,
Mark.
I have a macro (code below) that is assigned to a button in an Excel 2010 Macro Enabled Template (.xlsm). I push the button and it copies a pre-formatted row from one worksheet to another and pastes it beneath a row with a specified value in a column.
Code:
Option Explicit
Sub Insert_Line_1_Pre_Deployment_Preparation()
Dim FindString As String
Dim Rng As Range
With ActiveSheet.Unprotect
'Enter Search Value between the ""
FindString = "1"
If Trim(FindString) <> "" Then
'Set The Search Range Between The ""
With ActiveSheet.Range("A:A")
Set Rng = .Find(What:=FindString, After:=.Cells(1, 1), LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
MatchCase:=False)
'Moves To The Cell With The Value In
If Not Rng Is Nothing Then
Application.GoTo Rng, True
'Copys The Row Specified
Sheets("Format Control").Rows(19).Copy
'Inserts The Row Copied Beneath The Row Found With The Value In
Rng.Offset(1).EntireRow.Insert
Rng.Offset(1).EntireRow.PasteSpecial
'Moves The Active Cell 1 Row Down and 2 Cells To The Right
Rng.Offset(1, 2).Select
Else
End If
End With
End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowInsertingRows:=True, AllowDeletingRows _
:=True
End With
ActiveWindow.SmallScroll Down:=-8
End Sub
It works perfectly as long as I don't delete a row and then want to use this button to copy\insert a pre-formatted row again. If I do I am presented with the following error box upon execution:
Code:
Microsoft Visual Basic
Run-time error '-2147417848 (80010108)':
Method 'Insert' of object 'Range' failed
This code works fantastic in Excel 2003 but we are about to migrate to Office 2010 (the error being in Execl 2010) and I really need the skills of some of the fantastic members on here to help me out.
Thank you for your time and any help,
Mark.