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
Hello HansV.
Sorry to bother you again (in fact I thought i sent this once already but it doesn't show that i did).
I tested this at home and it worked, tried it at work on the spreadsheet i will actually use and it does not.
It says I have to debug it and highlights this part
Rows(CurRow - 1).SpecialCells(xlCellTypeFormulas).Resize
It will unlock and insert a row but won't carry the formula. Any clue as to what is wrong. It calls it an error 1004, an application or object error.
The most likely explanation is that the row above the one that is inserted by the code does not contain any formulas.
it does have formulas.
row 20 is where my formulas start and I made the header row 19 (but I played with this some sam result every time)
it says application defined or object defined error. with the error code beint 1004. I did test your demo to see what it would do if i inserted on the first line and i got the 1004 error but it said cell could not be located or somthing to that affect.