Guest User

Untitled

a guest
Feb 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. Public carry As Boolean
  2.  
  3. Function AnsCount(range, trg)
  4. Dim res()
  5. res = EnumCombi(range, trg)
  6. AnsCount = UBound(res)
  7. End Function
  8.  
  9. Function NextCells(range, crnt)
  10. Dim min
  11. Dim max
  12. min = range.Row
  13. max = range.Row + range.rows.Count - 1
  14.  
  15. Dim results()
  16. ReDim results(UBound(crnt))
  17. For i = 1 To UBound(crnt)
  18. If carry Then
  19. If crnt(i).Row = max Then
  20. Set results(i) = range.Cells(min, crnt(i).Column)
  21. carry = True
  22. Else
  23. Set results(i) = range.Cells(crnt(i).Row + 1, crnt(i).Column)
  24. carry = False
  25. End If
  26. Else
  27. Set results(i) = crnt(i)
  28. carry = False
  29. End If
  30. Next i
  31. NextCells = results
  32. End Function
  33.  
  34. Function Total(xs)
  35. Dim result
  36. result = 0
  37. For Each x In xs
  38. If IsEmpty(x) Then
  39. Else
  40. result = result + x.Value2
  41. End If
  42. Next x
  43. Total = result
  44. End Function
  45.  
  46. Function EnumCombi(range, trg)
  47. Dim crnt()
  48. ReDim crnt(range.Columns.Count)
  49. For i = 1 To range.Columns.Count
  50. Set crnt(i) = range.Cells(range.Row, range.Column + i - 1)
  51. Next i
  52.  
  53. Dim size
  54. size = 0
  55. Dim results()
  56. ReDim results(size)
  57. Do
  58. If Total(crnt) = trg Then
  59. ReDim Preserve results(size + 1)
  60. results(size) = crnt
  61. size = size + 1
  62. End If
  63. carry = True
  64. crnt = NextCells(range, crnt)
  65. Loop Until carry
  66. EnumCombi = results
  67. End Function
Add Comment
Please, Sign In to add comment