A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
If you just want the result of the formula, try
ActiveSheet.Range("E" & r).Value = ActiveSheet.Range("E1").Value
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi
I have a protected sheet contain formula in each row depends to above row( for example C2=C1+1; C3=C2+1;...).and cells contained these formula are locked.
I like to allow users to insert row everywhere by keeping formula without unprotecting the sheet. When I am clicking "insert row" while protecting the sheet, users could insert a row but the locked inserted cells are not including any formula and excel doesn't permit to copy formula of above cells. is there any solution?
Thanks
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
If you just want the result of the formula, try
ActiveSheet.Range("E" & r).Value = ActiveSheet.Range("E1").Value
In the first place: to prevent the users from viewing the macro and seeing the password to unlock the sheet, you must protect the Visual Basic project of the workbook with a password.
Let's say the password is "secret". The following macro will insert a row and fill down the formula in column C:
Sub InsertARow()
Dim r As Long
On Error GoTo ErrHandler
' Get the row number
r = Range("C10").Value
' Unprotect the sheet
ActiveSheet.Unprotect Password:="secret"
' Insert a row
Range("C" & r).EntireRow.Insert
' Fill down the formula from above the inserted row to below it
Range("C" & (r - 1) & ":C" & (r + 1)).FillDown
ExitHandler:
' Protect the sheet again
ActiveSheet.Protect Password:="secret"
' Get out
Exit Sub
ErrHandler:
' Report the error to the user
MsgBox Err.Description, vbExclamation
' Always go past the exit handler section
Resume ExitHandler
End Sub
Actually I came back at this fresh and started messing with it again and it worked. Whoo Hoo! Thanks a lot. I had been banging my head for a while on this one.
Good to hear that. Thanks for the feedback.
Hey HansV
Sorry to bother you again but when I actually go to put the code in the spreadsheet it doesn't work. Says it needs to de bug. When I got ot it this is what it shows (ok thought this thing had highligting, but basically what I have bolded is what is highlighted when excel teels me what needs to be fixed) but I don't know what i should do to fix this.
Option Explicit
Sub InsertRow()
Const HeaderRow = 5
Dim CurRow As Long
Dim LastRow As Long
CurRow = ActiveCell.Row
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
If CurRow <= HeaderRow + 1 Or CurRow >= LastRow Then
Beep
Exit Sub
End If
ActiveSheet.Unprotect Password:="secret"
Cells(CurRow, 1).EntireRow.Insert
Rows(CurRow - 1).SpecialCells(xlCellTypeFormulas).Resize(2).FillDown
ActiveSheet.Protect Password:="secret"
End Sub
This tested out fine at home buit now that I am trying to get it to work on the actual spreadsheet at work it wont. I would guess it might have to do with the formulas cause this is a far bigger sheet, but I don't know why it would. It inserts the row and unprotects the sheet but doesn't fill the formulas in or reprotects the sheet.