title: Referencing the same array in different Subs in VBA Excel
body: <p>I have a function that fills a certain array with cell values depending on which OptionButton is selected. How would I reference those same arrays in a seperate function which would feed those values back into the cells? Here is my (working) code so far. </p>
  
  <pre><code>Private Sub CommandButton1_Click()
  Dim wave1Array(0 To 30) As String
  Dim wave2Array(0 To 30) As String
  Dim wave3Array(0 To 30) As String
  Dim wave4Array(0 To 30) As String
  Dim wave5Array(0 To 30) As String
  Dim rng As Range
  Dim cell As Range
  Dim counter As Long
  
  Set rng = Range("B2", "AF2")
  counter = 0
  
  If OptionButton6.Value = True Then
      For Each cell In rng
      wave1Array(counter) = cell.Value
      counter = counter + 1
  Next cell
  ElseIf OptionButton7.Value = True Then
      For Each cell In rng
      wave2Array(counter) = cell.Value
      counter = counter + 1
  Next cell
  ElseIf OptionButton8.Value = True Then
      For Each cell In rng
      wave3Array(counter) = cell.Value
      counter = counter + 1
  Next cell
  ElseIf OptionButton9.Value = True Then
      For Each cell In rng
      wave4Array(counter) = cell.Value
      counter = counter + 1
  Next cell
  ElseIf OptionButton10.Value = True Then
      For Each cell In rng
      wave5Array(counter) = cell.Value
      counter = counter + 1
  Next cell
  End If
  
  End Sub
  </code></pre>