简体   繁体   中英

Case Statement Not Working for me

I'm having trouble understanding what is going wrong with my case statement below...

Select Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count

    Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count > 7
        protoWorksheet.Cells(rowCounter, 12) = "X"
    Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count = 7
        protoWorksheet.Cells(rowCounter, 11) = "X"
    Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count = 6
        protoWorksheet.Cells(rowCounter, 10) = "X"
    Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count = 5 Or 4
        protoWorksheet.Cells(rowCounter, 9) = "X"
    Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count = 3
        protoWorksheet.Cells(rowCounter, 8) = "X"
End Select

The only successful case it goes into is 5 or 4 but only for the 4 . I'm not sure where I'm going wrong here... Thanks in advance.

Remove aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count from each case line. The Select Case sets the value to be tested and the Case lines just need the expected output.

Also when using OR just list the values comma separated.

Select Case aFunction.getListOfWords.Intersect(aUTL.getListOfWords).Count

    Case  > 7
        protoWorksheet.Cells(rowCounter, 12) = "X"
    Case  7
        protoWorksheet.Cells(rowCounter, 11) = "X"
    Case  6
        protoWorksheet.Cells(rowCounter, 10) = "X"
    Case  5, 4
        protoWorksheet.Cells(rowCounter, 9) = "X"
    Case  3
        protoWorksheet.Cells(rowCounter, 8) = "X"
End Select

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM