Dim arr, i, s%
arr = Range([a20], [a65536].End(3))
For i = 1 To UBound(arr)
s = s + 1
If arr(i, 1) >= 100 Then
Cells(i + 19, 4) = "通過"
ElseIf (arr(i, 1) < 100) * (arr(i, 1) >= 0) Then
Cells(i + 19, 4) = "不通過"
Else
Cells(i + 19, 4) = ""
End If
Next
[c20].Resize(UBound(arr)) = arr
End Sub作者: samwang 時間: 2021-9-7 12:21
Sub test()
Dim arr, i, s%
arr = Range([a20], [a65536].End(3))
For i = 1 To UBound(arr)
s = s + 1
If arr(i, 1) >= 100 Then
arr(s, 1) = "通過"
ElseIf (arr(i, 1) < 100) * (arr(i, 1) >= 0) Then
arr(s, 1) = "不通過"
Else
arr(s, 1) = ""
End If
Next
[c20].Resize(UBound(arr)) = arr
End Sub作者: wayne0303 時間: 2021-9-7 13:11
Sub iif2()
Dim arr, i
arr = Range([a20], [a65536].End(3))
For i = 1 To UBound(arr)
If arr(i, 1) >= 100 Then
arr(i, 1) = "通過"
ElseIf arr(i, 1) >= 0 Then
arr(i, 1) = "不通過"
Else
arr(i, 1) = ""
End If
Next
[c20].Resize(UBound(arr)) = arr
End Sub作者: wayne0303 時間: 2021-9-7 15:43
Sub iif2()
Dim arr, i
arr = Range([a20], [a65536].End(3))
For i ...
ML089 發表於 2021-9-7 14:08
作者: ML089 時間: 2021-9-7 16:43
Select Case 來替代 If else
Sub iif4()
Dim arr, i
arr = Range([a20], [a65536].End(3))
For i = 1 To UBound(arr)
Select Case arr(i, 1)
Case Is >= 100
arr(i, 1) = "通過"
Case Is >= 0
arr(i, 1) = "不通過"
Case Else
arr(i, 1) = ""
End Select
Next
[c20].Resize(UBound(arr)) = arr
End Sub作者: wayne0303 時間: 2021-9-7 17:55
若是一個變數只有2~3種判斷,用 IF 比較簡單,3個以上判斷可以考慮用 Select Case
像下列範例之多項判斷用IF就很累吧!
Select Case number
Case 1 To 5
Debug.WriteLine("Between 1 and 5, inclusive")
' The following is the only Case clause that evaluates to True.
Case 6, 7, 8
Debug.WriteLine("Between 6 and 8, inclusive")
Case 9 To 10
Debug.WriteLine("Equal to 9 or 10")
Case Else
Debug.WriteLine("Not between 1 and 10, inclusive")
End Select作者: 准提部林 時間: 2021-9-11 11:39
Sub iif3()
Dim arr, i&,V,T$
arr = Range([a20], [a65536].End(3))
For i = 1 To UBound(arr)
v= arr(i,1)
t=switch(v>=100,"通過",v>=0,"不通過",v=v,"")
arr(i, 1) = t
Next
[c20].Resize(UBound(arr)) = arr
End Sub作者: wayne0303 時間: 2021-9-13 14:15