如何在vba中使用已定义的函数

时间:2016-02-29 13:29:58

标签: vba

我会尝试为锦标赛做一个随机配对,我宣布一个函数将它用作主要功能。 (函数的顺序是否重要?)到目前为止我只学习了Java,所以语法对我来说很新鲜。

Public Sub IsInArray(counter As Integer, number As Integer, tm() As Integer, tf As Boolean)
While counter <= tm.Length
    If number = tm(counter) Then
        tf = True
    End If
    counter = counter + 1

End Sub

Public Sub test()

'declare variable
Dim tf1 As Boolean
tf1 = False
Dim tf2 As Boolean
tf2 = False
Dim ac1 As Integer
ac1 = 0
Dim ac2 As Integer
ac2 = 1
Dim i As Integer
i = 0
Dim r1 As Integer
Dim r2 As Integer
Dim columnLength As Integer
columnLength = (ws.Range("G" & Rows.Count).End(xlUp).Row)
Dim k As Integer
k = ((ws.Range("G" & Rows.Count).End(xlUp).Row) - 1)
Dim Matches(1 To 50) As Integer
Dim team(1 To 100) As Integer
 Dim j As Integer
j = k / 2




'count through the team
While i < j
r1 = ((columnLength - 1 + 1) * Rand + 1)
r2 = ((columnLength - 1 + 1) * Rand + 1)
    If Not r1 = r2 And Not IsInArray(0, r1, Matches, tf1) And Not IsInArray(0, r2, Matches, tf2) Then
        team(ac1) = r1
        team(ac2) = r2
        Cells(7, i).Value = ("Team" And r1 And "vs." And "Team" And r2)
        i = i + 1
        ac1 = ac1 + 2
        ac2 = ac2 + 2
    End If



End Sub

0 个答案:

没有答案