title: find which elements of ana array add up to a sum [vba]
body: <p>what i want to do: i have a list of data and i want to know which of the values add up to a specific sum [ie. 1.61], i would like to know all the combinations [ie. i doesn't matter how many numbers i have to add up], the anwsers should be indicated somehow</p>
  
  <p>what i did: i multiplied the data, put it into three arrays and went through each element; then checked if the soulution came up before, if not the combination is indicated in a cell</p>
  
  <pre><code>Sub po_mojemu()
  Dim macierz1(1 To 30)
  Dim macierz2(1 To 30)
  Dim macierz3(1 To 30)
  Dim ostatnia_dane As Long
  Dim ostatnia As Long
  
  ostatnia_dane = Range("b" &amp; Rows.Count).End(xlUp).Row
  
  For i = 1 To ostatnia_dane
          macierz1(i) = Cells(i, 2).Value
          macierz2(i) = Cells(i, 2).Value
          macierz3(i) = Cells(i, 2).Value
  Next i
  
  For Each element1 In macierz1
    For Each element2 In macierz2
      For Each element3 In macierz3
          If element1 + element2 + element3 = 1.61 Then
              Set c = Range("f:f").Find(What:=element1 &amp; " : " &amp; element2 &amp; " : " &amp; element3)
                  If c Is Nothing Then
                      ostatnia = Range("f" &amp; Rows.Count).End(xlUp).Row + 1
                      Cells(ostatnia, 6) = element1 &amp; " : " &amp; element2 &amp; " : " &amp; element3
                  End If
          End If
      Next element3
  Next element2
  Next element1
  
  End Sub
  </code></pre>
  
  <p>what is the problem: it's not effective and it looks only at a certain case [ie. i know that there will be 30 rows of data, and i need 3 numbers that make up the sum]</p>
  
  <p>i would appreciate any help that would make this code more flexible</p>