title: Calling type variables from another sub
body: <p>Hi I have a series of subroutines as follows:</p>
  
  <ol>
  <li><p>DataCollection() : Collects data from the spreadsheet and writes it to custom type variables.</p></li>
  <li><p>NewSub() : Does something else, but not relevant to the question.</p></li>
  </ol>
  
  <p>I would like to keep the same variables previously declared, and having values assigned in the second sub. I think I have to make them global variables somehow, but could not work it out so far, whatever I do I get the variable not defined error. My code is as follows:</p>
  
  <pre><code>Option Explicit
  
  Public Type Trucks
      NumberOfAxles As Integer
      AxleWeights(15) As Double
  End Type
  
  Public Sub DataCollection()
  
  Dim NumberOfTrucks As Integer
  Truck(10) As Trucks
  Dim i, j, k As Integer
  
  'Determine Number of Trucks
  NumberOfTrucks = Cells(6, 8)
  
  'Populate Truck Arrays (Trucks 1 to 5)
  
  k = 0
  For i = 1 To 5
      Truck(i).NumberOfAxles = Cells(9, 4 + 4 * k)
      k = k + 1
  Next i
  
  k = 0
  For i = 1 To 5
      For j = 1 To Truck(i).NumberOfAxles
          Truck(i).AxleWeights(j) = Cells(31 + j, 3 + 4 * k)
      Next j
      k = k + 1
  Next i
  
  End Sub
  
  Public Sub NewSub()
  
  For i = 1 To Truck(10).NumberOfAxles
      Cells(27 + i, 22) = Truck(10).AxleWeights(i)
  Next i
  
  End Sub
  </code></pre>
  
  <p>Any ideas would be most welcome! Thanks!</p>