你能帮我找一个三个数字的组合,并在给定的列表中加上X的总和。
Fx列表1,2,3,4,5,6,7,8,9中的一组树数为6,将为1 + 2 + 3
我可以使用一组两个数字,以下面的VBA代码
Function Set(list As Range, x As Integer)
k = 0
j = 0
For Each i In list
If x = list(1 + k) + list(list.Rows.Count - j) Then
Set = k & ", " & j
ElseIf list(1 + k) + list(list.Rows.Count - j) > x Then
j = j + 1
ElseIf list(1 + k) + list(list.Rows.Count - j) < x Then
k = k + 1
End If
Next i
End Function
祝你好运 Kresten
答案 0 :(得分:0)
可能,
Function myPair(list As Range, x As Integer)
Dim vDB, vR(1 To 3)
Dim i As Long, n As Long, k As Long
vDB = list
n = UBound(vDB, 1)
For i = 1 To n
For j = i + 1 To n
For k = j + 1 To n
If vDB(i, 1) + vDB(j, 1) + vDB(k, 1) = x Then
vR(1) = vDB(i, 1): vR(2) = vDB(j, 1): vR(3) = vDB(k, 1)
myPair = Join(vR, ",")
End If
Next k
Next j
Next i
End Function