I keep getting this error message when I try to run this macro:
(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?
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?