Select Statement中的额外条件

时间:2015-12-12 16:31:24

标签: excel-vba vba excel

我有一个select语句,其条件基于单元格的第一个字母/数字。我的问题是我的细胞的值可能会落在两个不同的病例上。例如,具有247L和250L的单元格将返回“B”,但是我希望它们在不同的条件下执行。我想嵌套一个选择案例或IF语句,它只返回所有以2开头的单元格的“B”,如果它们高于250L,则返回不同的值。

Option Compare Text
Sub Main()
    Dim FinalRow As Long
    Dim i As Long
    'Loop to find cells with value to use
    FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To FinalRow
    'Output results to cells and columns
    Cells(i, 14).Value = mBlineCTG(i) & findShpc(i)
    Cells(i, 16).Value = findTrainId(i)
    'Write Column Headers
    Range("N1").Value = "SH_CAT"
    Range("P1").Value = "TRAIN_ID"
    Next
End Sub

Public Function mBlineCTG(i As Long)
Dim cRange 
Dim shpCt As String
 ' determine category by first digit of cell
    Select Case UCase(Left(Cells(i, 13).Value, 1))
        Case "D"
        shpCt = "D"
        Case "0"
            shpCt = "V"
        Case "1", "R", "E", "F"
               shpCt = "S"
        Case "I"
            shpCt = "I"
        Case "2" 
           Select case cRange   'checking for range within, doesnt work
               case 200L to 249L
                 shpCt = "B"
               case else
                 shpct = "F"
           end select   
        Case "3"
            shpCt = "F"
        Case Else
            shpCt = ""
    End Select

   mBlineCTG = shpCt

End Function

1 个答案:

答案 0 :(得分:0)

你只需要在每个可能的Case语句中加上一个If ...除非我在你的问题中遗漏了什么?希望这会有所帮助。