Hello Everyone,
First of all, I have to say, this forum has helped me immensely and I am so thankful for all the help offered here!
I have not been able to find a solution to this despite the extensive research I have attempted. I have a VBA code that will prevent the user from modifying any of the cells that contain a formula (code below). I am using this in a data collection excel template I developed and it will be used to create workbooks for nurses so they can track healthcare related information but I don't want them inadvertently delete any formulas. They will need the option to delete the row if needed in case they make an entry by mistake. This code is preventing me from doing so.
Also, protecting the worksheet is not an option because it will not allow the tool to work as intended.
I am stumped...
'Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim rCell As Range
Set rCell = Nothing
If Target.Cells.Count = 1 And Target.HasFormula Then
ActiveCell.Offset(0, 1).Select
MsgBox "Formulas cannot be modified"
'Allow ActiveRow.Delete = True'
'or?'
'Activerow.AllowDeletingRows = True'
ElseIf Target.Cells.Count > 1 Then
On Error Resume Next
Set rCell = Target.Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0
If Not rCell Is Nothing Then ActiveCell.Offset(0, 1).Select
End If
End Sub
First of all, I have to say, this forum has helped me immensely and I am so thankful for all the help offered here!
I have not been able to find a solution to this despite the extensive research I have attempted. I have a VBA code that will prevent the user from modifying any of the cells that contain a formula (code below). I am using this in a data collection excel template I developed and it will be used to create workbooks for nurses so they can track healthcare related information but I don't want them inadvertently delete any formulas. They will need the option to delete the row if needed in case they make an entry by mistake. This code is preventing me from doing so.
Also, protecting the worksheet is not an option because it will not allow the tool to work as intended.
I am stumped...
'Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim rCell As Range
Set rCell = Nothing
If Target.Cells.Count = 1 And Target.HasFormula Then
ActiveCell.Offset(0, 1).Select
MsgBox "Formulas cannot be modified"
'Allow ActiveRow.Delete = True'
'or?'
'Activerow.AllowDeletingRows = True'
ElseIf Target.Cells.Count > 1 Then
On Error Resume Next
Set rCell = Target.Cells.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0
If Not rCell Is Nothing Then ActiveCell.Offset(0, 1).Select
End If
End Sub