I'm having a problem with a piece of code. I have searched and tried various solutions but nothing seems to work.
I also don't understand why sometimes this code works perfectly, for example when restarting excel and opening workbook again. And then after I have run few other codes (workbook contains many) I keep getting "Object variable or with block variable is not set" error.
Debug shows I have a problem with row "Worksheets("Leping").Range("A1:A10000").Find("lisa_kaasomanik", lookat:=xlPart).Activate"
Basically what I'm trying to do is to activate a certain cell and then insert new row according to active cell while copying formats from another row.
Can anyone please guide me to a solution?
I also don't understand why sometimes this code works perfectly, for example when restarting excel and opening workbook again. And then after I have run few other codes (workbook contains many) I keep getting "Object variable or with block variable is not set" error.
Debug shows I have a problem with row "Worksheets("Leping").Range("A1:A10000").Find("lisa_kaasomanik", lookat:=xlPart).Activate"
Basically what I'm trying to do is to activate a certain cell and then insert new row according to active cell while copying formats from another row.
Can anyone please guide me to a solution?
Code:
Sub InsertRow()
Application.ScreenUpdating = False
ActiveSheet.Unprotect
Worksheets("Leping").Range("A1:A10000").Find("lisa_kaasomanik", lookat:=xlPart).Activate
ActiveCell.Offset(0, 0).EntireRow.Insert
ActiveCell.Offset(-1, 0).EntireRow.Copy
ActiveCell.Offset(0, 0).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.Protect
Application.ScreenUpdating = True
End Sub