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
Could you create a stripped-down copy of the workbook (without sensitive information) and make it available through one of the websites that let you upload and share a file, such as Microsoft OneDrive (https://onedrive.live.com), FileDropper (http://filedropper.com) or DropBox (http://www.dropbox.com). Then post a link to the uploaded and shared file here.
Or register at www.eileenslounge.com (it's free) and post a message in the Excel forum. You can attach files up to 250 KB to a post there (zipped if necessary).
I can see how you did everything in the demo but when I open a spreadsheet to duplicate the VBA code it does not work. Is there a setting or step I am missing or something? Also I tried the tables earlier as a suggestion from a friend it works only when unprotected. So this VBA looks like the viable option I just can't seem to get it to work for some reason.
I create my table, then create the VBA code, I enabled all macros, and saved my file as macros enabled, the little insert row button never comes up.
I really appreaciate your help and responsiveness, however, I will be away from the computer for a few hours so you may not hear from me in a little bit if you reply again.
Thanks
I have uploaded a sample workbook to DropBox:
https://www.dropbox.com/s/wco8l3hg02exii6/InsertDemo.xlsm
The worksheet has been protected with password secret. The VBA code is not protected.
The command button lets you insert a row if you select a cell in the data (below the first row with data). Formulas (in this example in column D only, but you could add more) will be copied automatically.
Another option would be to define a table. Excel will automatically propagate formulas in a table row when you insert a new row.