title: Passing Array to Sub ByRef in Excel VBA
body: <p>I am currently working on a project for my job. I have two Subs and want to fill an array with one of those and want to use it in the other Sub. Its hard to explain but here is the code so far:</p>
  
  <pre><code>Private Sub Find_CHNO(name As String, ByRef Myarray() As String)
  Dim filter As String
  Dim ws As Worksheet
  Dim rng As Range
  Dim i, j As Long
  
  Set ws = Sheets("Stoffdatenbank")
  Set rng = ws.Range("A1").CurrentRegion
  
  filter = name
  
  ReDim Myarray(4)
  
  For i = 1 To rng.Rows.count
      If InStr(1, rng.Cells(i, 2), filter) &gt; 0 Then
          For j = 1 To 4
              Myarray(j) = rng.Cells(i, j + 2)
          Next
      End If
  Next
  End Sub
  </code></pre>
  
  <p>And</p>
  
  <pre><code>Private Sub b_heizwert_calculate_Click()
  Dim wC, wH, wN, wO, Hi As Double
  Dim arr1(0 To 4), arr2(0 To 4), arr3(0 To 4) As String
  
  If arrL3(0) = "" Then
      Call Find_CHNO(arrL1(0), arr1)
      Call Find_CHNO(arrL2(0), arr2)
  
      MsgBox arr1(0)
      'wC = arrL1(1) * arr1(1)
  Else
  
  End If
  
  End Sub
  </code></pre>
  
  <p>Whenever I press on the Button that triggers the second Sub I get the following error: </p>
  
  <blockquote>
    <p>Compile Error: Incompatible Type: Data field or user-defined type expected</p>
  </blockquote>
  
  <p>The following is marked blue when the error occurs: The "arr1" in the following line: </p>
  
  <pre><code>Call Find_CHNO(arrL1(0), arr1)
  </code></pre>