【发布时间】:2015-07-10 12:48:40
【问题描述】:
我是 VBA 新手,因此提前感谢任何可以在这里帮助我的人。基本上,我正在使用改编的 Ron de Bruin 代码,当学生的出勤率低于特定水平时,自动向学生发送邮件,如特定的 Excel 单元格中显示的那样。到目前为止,一切都很好,Ron de Bruin 的东西会照顾这个。 但是我想添加另一个标准,基本上是只有在与出席者在同一行的不同单元格中还有一个字母“Y”时才发送邮件。 总而言之,我只希望邮件发送给满足两个条件的人,1)下降到某个水平以下,2)在另一个单元格中有一个“Y”,但目前的代码只考虑第一个条件.非常感谢。 Alun(代码如下)
Option Explicit
Private Sub Worksheet_Calculate()
Dim FormulaRange As Range
Dim NotSentMsg As String
Dim MyMsg As String
Dim SentMsg As String
Dim MyLimit As Double
NotSentMsg = "Not Sent"
SentMsg = "Sent"
'Above the MyLimit value it will run the macro
MyLimit = 80
'Set the range with Formulas that you want to check
Set FormulaRange = Me.Range("BH279:BH280")
On Error GoTo EndMacro:
For Each FormulaCell In FormulaRange.Cells
With FormulaCell
If IsNumeric(.Value) = False Then
MyMsg = "Not numeric"
Else
If .Value < MyLimit Then
MyMsg = SentMsg
If .Offset(0, 1).Value = NotSentMsg Then
Call Mail_with_outlook2
End If
Else
MyMsg = NotSentMsg
End If
End If
Application.EnableEvents = False
.Offset(0, 1).Value = MyMsg
Application.EnableEvents = True
End With
Next FormulaCell
ExitMacro:
Exit Sub
EndMacro:
Application.EnableEvents = True
MsgBox "Some Error occurred." _
& vbLf & Err.Number _
& vbLf & Err.Description
End Sub
【问题讨论】:
-
您可以使用
IF(AAA111="Y",percentage,1)序言来修正您的公式。如果你想提高你的知识,而不仅仅是解决这个问题,我推荐homework标签(不确定拼写)。 -
非常感谢理查德,我会在星期一试试这个,然后告诉你。如果您曾经竞选公职,您可以放心得到我的支持!
-
理查德谢谢,我先尝试下面的答案,因为我的知识有限,我不知道如何使用你的建议,在哪里粘贴 IF(AAA111="Y",percentage,1) 和我需要添加什么才能让它工作。如果您能详细说明,我将永远感激不尽。阿伦
-
我得到了替代方法,所以您不必浪费时间向我解释任何事情。非常感谢您的帮助。
标签: excel vba email multiple-conditions