最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vba - Send email based on column in Excel - Stack Overflow

programmeradmin1浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

To 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.

发布评论

评论列表(0)

  1. 暂无评论