I am using this macro in Excel to send an email based on input to specific cells. The issue is every cell between F3-F14 causes the email to send. Like A6 and D5. I want only the ones in the F column. Is that possible?
Private Sub Worksheet_Change(ByVal Target As Range)
Call notify
End Sub
Sub notify()
Dim rng As Range
For Each rng In Range("F3:F14")
If (rng.Value = 1) Then
Call mymacro
End If
Next rng
End Sub
Sorry for any formatting issues I'm on mobile.
I was expecting emails only when the items in column F updated but I get them for other columns too.
I am using this macro in Excel to send an email based on input to specific cells. The issue is every cell between F3-F14 causes the email to send. Like A6 and D5. I want only the ones in the F column. Is that possible?
Private Sub Worksheet_Change(ByVal Target As Range)
Call notify
End Sub
Sub notify()
Dim rng As Range
For Each rng In Range("F3:F14")
If (rng.Value = 1) Then
Call mymacro
End If
Next rng
End Sub
Sorry for any formatting issues I'm on mobile.
I was expecting emails only when the items in column F updated but I get them for other columns too.
Share Improve this question edited Feb 6 at 21:45 braX 11.8k5 gold badges22 silver badges37 bronze badges asked Feb 6 at 21:44 Zachary WZachary W 1 New contributor Zachary W is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 2- You may have a look onto the examples of the Worksheet change event in the documentation. – Shrotter Commented Feb 6 at 21:50
- @Shrotter if your only comment is "read the documentation", maybe you shouldn't have commented at all. – teylyn Commented Feb 6 at 23:11
1 Answer
Reset to default 0To do what you describe, try
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target,Range("F3:F14")) is Nothing then
If (Target.Value = 1) Then
Call mymacro
End If
End If
End Sub
This will only continue the change event if a cell in the specified range is change AND if that cell change has just resulted in the value 1.