Application-defined or object defined error

smichael

New Member
Joined
Jul 15, 2011
Messages
38
I keep getting this error message when I try to run this macro:

Code:
Sub Macro2()
ActiveSheet.Unprotect
'
' Macro2 Macro
'
' Keyboard Shortcut: Ctrl+x
'
Dim i As Long
Dim lrow As Long
Application.DisplayAlerts = False
lrow = Range("G" & Rows.Count).End(xlUp).Row
For i = 7 To lrow
    Cells(i, "G").Select
    Selection.Copy
    Cells(i, "K").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Cells(i, "G").Select
    Application.CutCopyMode = False
    Cells(i, "G").Select
    [COLOR=red]ActiveCell.FormulaR1C1 = "=RC[4]-RC[3]"[/COLOR]
    Cells(i, "G").Select
    Selection.Copy
    Cells(i, "K").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.Copy
    Cells(i, "G").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Cells(i, "J").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "0"
    Columns("K:K").Select
    Cells(i, "K").Activate
    Selection.Delete Shift:=xlToLeft
Next i
Application.DisplayAlerts = True
ActiveSheet.Protect
End Sub

(Error on red highlighted line)
It works perfectly in another excel document while I protect it, but won't work for this one when I copy and pasted it. Also, there is another macro running that protects the worksheet.

Any help?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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