Greetings contaminated,
That code wouldn't do what I need, so I must have explained it badly. This is the formula in columns N,P,R, and T on row 2: "=if(isblank($L2),"",$L2". The cell isn't protected though, so a user can enter another value. When my code runs to copy the last row, paste it to the next available row, in this case it copies row two and pastes it into row three, it won't necessarily copy the formula itself, if the user has changed it. But I always want it to copy the formula, regardless of whether a user over-writes it.
Here is the full code that is running, in case it helps:
'This code executes any time you move the cursor
'on the Records sheet.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Check to see if user has selected more than one row
'If yes, stop processing and exit
If Target.Rows.Count > 1 Then Exit Sub
'Check to see if the row is empty, if not, stop
'processing and exit
If Application.CountA(Target.EntireRow) <> 0 Then Exit Sub
'Check to see if the cell is in the third column
'if not, stop processing and exit. Otherwise, continue
If Target.Column = 3 Then
'Disable features and unprotect worksheet
Application.ScreenUpdating = False
Application.EnableEvents = False
ActiveSheet.Unprotect Password"secret"
'Copy the row above the first empty row, and paste
'it into the next available empty row
Range(Cells(Rows.Count, 2).End(xlUp).Offset(0, -1), _
Cells(Rows.Count, 2).End(xlUp).Offset(0, 66)).Copy _
Destination:=Cells(Rows.Count, 2).End(xlUp).Offset(1, -1)
'In the row you just pasted, clear the contents unless it
'starts with an equal sign, because then it's a formula
For Each Cell In Range(Cells(Rows.Count, 2).End(xlUp).Offset(0, -1), _
Cells(Rows.Count, 2).End(xlUp).Offset(0, 66))
If Cell <> "" Then
If Left(Cell.Formula, 1) <> "=" Then Cell.ClearContents
End If
'HERE
On Error Resume Next
Next Cell
'Insert the record creation date/time stamp
Cells(Rows.Count, 2).End(xlUp).Offset(0, -1).Value = Format(Now, "yyyy-mm-dd HH:mm")
'Re-enable features, and re-protect worksheet
ActiveSheet.Protect Password:="secret"
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
'End of program
End Sub
Bookmarks