【发布时间】:2017-03-06 16:31:20
【问题描述】:
我有一个非常简单的 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
【问题讨论】:
-
如何返回,只是在消息框中还是在工作表上?
-
在消息框中,不在工作表上。