Hello,
I would like cells in a specific column to be monitored for changes, then execute a macro on the row which has changed.
I found the below code from an older post, and it works, however when I enter data and click "enter" the selection goes to the next row and executes my macro on the wrong row. If I click "tab" instead of "enter", it works as expected.
I also have a button which executes my macro, so I would like it to work both ways.
Any suggestions on how to make this work in all circumstances, that being:
Paste this code in "ThisWorksheet":
I would like cells in a specific column to be monitored for changes, then execute a macro on the row which has changed.
I found the below code from an older post, and it works, however when I enter data and click "enter" the selection goes to the next row and executes my macro on the wrong row. If I click "tab" instead of "enter", it works as expected.
I also have a button which executes my macro, so I would like it to work both ways.
Any suggestions on how to make this work in all circumstances, that being:
- Hitting Enter
- HItting Tab
- Clicking Macro button
Paste this code in "ThisWorksheet":
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Index = 1 Then ' 1'st sheet in workbook
If Target.Column = 3 Or Target.Column = 4 Then ' 3'rd and 4th colums are active
Application.Run ("MyMacro") 'Change 'MyMacro to your Macro's name
End If
End If
If Sh.Index = 2 Then ' 2'st sheet in workbook
If Target.Column = 3 Or Target.Column = 4 Then ' 3'rd and 4th colums are active
Application.Run ("MyMacro") 'Change 'MyMacro to your Macro's name
End If
End If
End Sub