Dim a() As String Dim max As String Dim i As Integer a() = Split("3,5,2,1", ",") '生成一个测试数组 For i = LBound(a) To UBound(a) If a(i) > max Then max = a(i) Next Debug.Print max
Function max(ParamArray a()) As Double max = a(LBound(a)) Dim i As Long For i = LBound(a) To UBound(a) If max < a(i) Then max = a(i) Next End FunctionPrivate Sub Command2_Click() MsgBox max(2, 11, 5, 18, 3, 4, 9) End Sub
Dim max As String
Dim i As Integer
a() = Split("3,5,2,1", ",") '生成一个测试数组
For i = LBound(a) To UBound(a)
If a(i) > max Then max = a(i)
Next
Debug.Print max
max = a(LBound(a))
Dim i As Long
For i = LBound(a) To UBound(a)
If max < a(i) Then max = a(i)
Next
End FunctionPrivate Sub Command2_Click()
MsgBox max(2, 11, 5, 18, 3, 4, 9)
End Sub