我是一名VBA新手,因此在此先感謝任何能夠幫助我的人。基本上,我使用的是一種改編的Ron de Bruin代碼,當他們的出勤低於特定excel單元格顯示的特定級別時,會自動發送郵件給學生。到目前爲止,這麼好,Ron de Bruin的東西照顧這個。 但還有另一個標準,我想添加,基本上只發送郵件,如果在出席的同一行的不同單元格中也有字母'Y'。總之,我只希望郵件能夠滿足兩個標準的人,1)低於一定水平,2)在另一個單元中有'Y',但目前的代碼只佔第一個標準。非常感謝。阿倫(下面的代碼)根據多個條件從excel發送一封自動郵件
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」,百分比,1)'序言來修正你的公式。如果你想提高你的知識,而不是解決這個問題,我會推薦'家庭作業'標籤(不確定拼寫)。 – user3819867
非常感謝理查德,我會在星期一嘗試一下,讓你知道。如果您曾經擔任公職,您可以放心支持我! – Alun
理查德謝謝,即時嘗試下面的答案,因爲我的知識是如此有限,我不知道如何使用您的建議,在哪裏粘貼中頻(AAA111 =「Y」,百分比,1)以及我需要添加什麼它工作。如果你能詳細說明,我會永遠感激。 Alun – Alun