Use OnKey
. Do one of the following:
1) Place this in the ThisWorkbook module (this will take over the enter key when you open the workbook and put it back to normal when you close):
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnKey "~"
End Sub
Private Sub Workbook_Open()
Application.OnKey "~", "AutoIncrement"
End Sub
--OR--
2) Add this to a module and call CatchEnter
it to toggle the behavior:
Public blnCatchEnter As Boolean
Public Sub CatchEnter()
If blnCatchEnter Then
Application.OnKey "~"
blnCatchEnter = False
Else
Application.OnKey "~", "AutoIncrement"
blnCatchEnter = True
End If
End Sub
Next, add this macro to a module:
Public Sub AutoIncrement()
If TypeName(Selection) = "Range" Then
Dim lngRow As Long
lngRow = Selection.Row + 1
Range("A" & lngRow).Formula = "=ROW()-7"
Range("B" & lngRow).Select
End If
End Sub
Although, I agree with @BruceWayne that you may not want to take over the Enter
key this way. Assigning a shortcut to AutoIncrement
will be safer.