所以我想讓我的宏在一張表中分析一些數據。數據在單元格B2到B6上,數字在0和4之間(小數)。Select Case wrong輸出
我想不出我在做什麼錯誤的代碼,它工作完全正常使用一組不同的在不同細胞的條件下,我圖所示
此代碼:
Sub Salmondepthoutlet()
Dim score As Double, result As String
Dim Rng As Range, i As Long
i = 0
With Sheets("Vertical")
For Each Rng In .Range("B7:B16")
score = Rng.Value
Select Case score
Case Is >= 0.15
result = "1"
Case 0.11 To 0.14
result = "0.6"
Case 0.08 To 0.1
result = "0.3"
Case Is <= 0.07
result = "0"
End Select
.Range("B26").Offset(i).Value = result
i = i + 1
Next Rng
End With
End Sub
但是這個代碼不(沒有出現在B21的輸出&結果是錯誤的,其他人)提前
Sub Salmonvelocityoutlet()
Dim score As Double, result As String
Dim Rng As Range, i As Long
i = 0
With Sheets("Vertical")
For Each Rng In .Range("B2:B6")
score = Rng.Value
Select Case score
Case Is >= 3
result = "0"
Case 2.99 To 2.6
result = "0.3"
Case 2.59 To 2.09
result = "0.6"
Case Is <= 2
result = "1"
End Select
.Range("B21").Offset(i).Value = result
i = i + 1
Next Rng
End With
End Sub
感謝您的H elp &時間
應該'.Range(「B2:B6」)'是'.Range(」 B7:B16「)' –
不,這是正確的範圍,原來在現在編輯的問題中弄錯了。 – Lilou
您的編輯代碼[適用於我](http://i.stack.imgur.com/S4zwf.jpg)。你的細胞有什麼價值? (你可以複製/粘貼一些數據)?請注意,它可能永遠不會在'B21'中返回一個值,因爲您正在通過'i'單元格進行抵消。 – BruceWayne