我有一個非常簡單的Excel宏,它檢查單元格範圍內的單元格的參考範圍中每個值的存在。如果找不到參考範圍的值,則會顯示一條消息,指出未找到該值。然後用戶必須點擊好的檢查才能繼續下一個項目。我想修改宏來檢查所有的值,並只返回所有檢查完成後找不到的列表。建議?Excel宏 - 返回符合條件的項目列表
當前代碼:
Sub ChkAfternoonAssignmentsV2()
Dim dayToChk As Variant
Dim i As Variant
Dim r As Range
Dim p As Variant
ReEnter:
dayToChk = InputBox("Which day (use 3-letter abbreviation) would you like to check afternoon assignments?")
If dayToChk = "Mon" Then
Set r = ActiveSheet.Range("MonAft_MA_Slots")
ElseIf dayToChk = "Tue" Then
Set r = ActiveSheet.Range("TueAft_MA_Slots")
ElseIf dayToChk = "Wed" Then
Set r = ActiveSheet.Range("WedAft_MA_Slots")
ElseIf dayToChk = "Thu" Then
Set r = ActiveSheet.Range("ThuAft_MA_Slots")
ElseIf dayToChk = "Fri" Then
Set r = ActiveSheet.Range("FriAft_MA_Slots")
Else
MsgBox dayToChk & " is not in the expected format. Try Mon, Tue, Wed, Thu, or Fri."
GoTo ReEnter
End If
Dim AckTime As Integer, InfoBox As Object
Set InfoBox = CreateObject("WScript.Shell")
AckTime = 1
Select Case InfoBox.Popup("Checking MA Assignments", _
AckTime, "Checking MA Assignments", 0)
Case 1, -1
End Select
For Each i In Sheets("Control").Range("MA_List")
If WorksheetFunction.CountIf(r, i) < 1 Then
If i <> "OOO" Then
MsgBox i & " is not assigned"
End If
ElseIf WorksheetFunction.CountIf(r, i) > 1 Then
If i <> "OOO" Then
MsgBox i & " is assigned more than once. Did you really mean to do that?"
End If
End If
Next i
返回如何,只是在消息框中或在紙張? – SJR
在消息框中,而不是在工作表上。 –