Select Case vba中的多个语句

我想使用excel vba中的Select Case选项来过滤正确的数据。 我做了以下几点:

For i = 2 To LastRow StartTime = Worksheets("Task input").Cells(1 + i, 9) Status = Worksheets("Task input").Cells(1 + i, 14) Select Case StartTime And Status Case TimeWindowBound1 To TimeWindowBound2 And "Planned" Worksheets("Performance output").Cells(5, 2) = Worksheets("Performance output").Cells(5, 2) + 1 End Select Next i 

他比较StartTime和状态。 但是,这给了一个错误? 任何解决scheme

你不能直接在select的情况下做到这一点

(select案例的文档https://msdn.microsoft.com/en-us/library/cy37t14y.aspx

select案例只能在一个variables上工作。 但是这里的解决scheme并不复杂:

 Select Case StartTime Case TimeWindowBound1 To TimeWindowBound2 If Status = "Planned" then Worksheets("Performance output").Cells(5, 2) = Worksheets("Performance output").Cells(5, 2) + 1 End Select 

真的,我很惊讶你的代码。 我还没有find像这样的东西。

你需要知道的一件事就是SELECT CASE [condition] AND [condition]不能在任何地方使用。

但是你需要检查两个,所以尝试如下:

 Public Sub testSelect() Dim sDate As Date Dim sString As String 'Set test date sDate = "10/02/2014" 'Set test string sString = "select" 'First select date, because it need to check in a range Select Case sDate 'If it is in desire range, check string Case "10/01/2014" To "10/30/2014" 'If string is equal, show message for True. If sString = "select" Then MsgBox ("True") 'Else show message for False Else MsgBox ("False") End If End Select End Sub