Excel VBA - Auto run macro when cell change

preview_player
Показать описание
How to auto update a particular worksheet when a particular cell is selected + How to auto update a particular worksheet when the contents in a particular cell is changed?

Syntax:
1. When selection changed
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Sheet8.Cells(7, "F") = ActiveCell Or Sheet8.Cells(8, "F") = ActiveCell Or Sheet8.Cells(10, "F") = ActiveCell Then
MsgBox ("Access Denied")
Sheet8.Cells(5, "F").Select
End If
End Sub

2. When contents changed (*replace "less than" with mathematical operator)
Private Sub Worksheet_Change(ByVal Target As Range)
If Sheet8.Cells(9, "F") "less than" 5 Then
MsgBox ("The loan tenure must be at least (more than or equal to) 5 years")
Sheet8.Cells(9, "F") = 5
End If
End Sub
Рекомендации по теме