从某列中找出总和等于某值的数
各位好!已知总和T,求从Excel某列中找出某些数的和刚好等于T的数。
Thanks
[解决办法]
给楼主一个较通用的,所有可能出现的和。
只要改改就能达成楼主的目的。
假设数据在A列
Sub macro1()
Dim b, arr, num As Long, i As Long, r As Long, c As Long, dic As Object, d, e As String
Set dic = CreateObject("scripting.dictionary")
b = [a1].CurrentRegion
num = 15 'ubound(b)
dic("") = 0
For i = 1 To num
arr = dic.keys
For Each d In arr
e = Replace(Trim(d & " " & b(i, 1)), " ", "+")
dic(e) = dic(d) + b(i, 1)
Next
Next
arr = Filter(dic.keys, "+")
ReDim brr(65535, UBound(arr) \ 65535)
For i = 0 To UBound(arr)
brr(r, c) = arr(i) & "=" & dic(arr(i))
r = r + 1
If r = 65535 Then r = 0: c = c + 1
Next
[c1].Resize(65536, c + 1) = brr
MsgBox "Ok"
End Sub
[解决办法]
递归?