Excel宏 - 返回符合条件的项目列表

时间:2017-03-03 18:34:34

标签: excel vba excel-vba

我有一个非常简单的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

2 个答案:

答案 0 :(得分:1)

已编译但未经过测试:

arr[i].split()

答案 1 :(得分:1)

你可以试试这个

func areKeysConsistentSwift(_ certificate : String,
                            privateKey : String,
                            password : String) -> Int32 {

    var result: Int32 = 0
    var certificateCString = certificate.utf8CString
    var privateKeyCString = privateKey.utf8CString
    var passwordCString = password.utf8CString


    certificateCString.withUnsafeMutableBytes { certUMRBP in
        privateKeyCString.withUnsafeMutableBytes { pkUMRBP in
            passwordCString.withUnsafeMutableBytes { passUMRBP in

                result = areKeysConsistent(
                    certUMRBP.baseAddress!.bindMemory(to: UInt8.self, capacity: certUMRBP.count),
                    UInt32(certUMRBP.count),
                    pkUMRBP.baseAddress!.bindMemory(to: UInt8.self, capacity: pkUMRBP.count),
                    UInt32(pkUMRBP.count),
                    passUMRBP.baseAddress!.bindMemory(to: Int8.self, capacity: passUMRBP.count)

                )
                print ("-------1--------")
                print (certUMRBP)
                print ("---------------")

                print ("-------2--------")
                print (pkUMRBP)
                print ("---------------")

                print ("-------3--------")
                print (passUMRBP)
                print ("---------------")

            }
        }
    }
    return Int32(result)

}