PDA

View Full Version : [SOLVED] Execute Macro on Cell Change



mikeoly
06-03-2019, 07:36 AM
Hello,
I've spent quite a bit of time researching this, but haven't found anything super helpful.

Goal: Execute macro on cell value change.
Current: Executes macro on target cell selection

Any ideas? Happy Monday!


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address = "$E$8:$G$8" Then
Sheets("Account Details").Range("ExpirationDate").Formula = "=IF(E8="""","""",DATEVALUE(MONTH(E8)&"" / ""&DAY(E8)&"" / ""&(YEAR(E8)+1)))"
End If

End Sub

大灰狼1976
06-03-2019, 07:55 AM
Hi mikeoly!
not sure, change "Worksheet_SelectionChange" to "Worksheet_Change" and try again.

xld
06-03-2019, 09:13 AM
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Me.Range = "$E$8:$G$8") Is Nothing Then

Worksheets("Account Details").Range("ExpirationDate").Formula = "=IF(E8="""","""",DATEVALUE(MONTH(E8)&"" / ""&DAY(E8)&"" / ""&(YEAR(E8)+1)))"
End If
End Sub

Artik
06-03-2019, 01:45 PM
(...)
If Not Intersect(Target, Me.Range = "$E$8:$G$8") Is Nothing Then
(...)
It should be
If Not Intersect(Target, Me.Range("$E$8:$G$8")) Is Nothing Then
Artik

Paul_Hossler
06-03-2019, 02:33 PM
Don't know about the formula, but I'd do



Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range ("$E$8:$G$8") Is Nothing Then Exit Sub

Worksheets("Account Details").Range("ExpirationDate").Formula = "=IF(E8="""","""",DATEVALUE(MONTH(E8)&"" / ""&DAY(E8)&"" / ""&(YEAR(E8)+1)))"

End Sub

mikeoly
06-04-2019, 09:57 AM
Thanks all! A few of the suggestions seemed to work well.