title: VBA Subroutine can't pass variable
body: <p>I am having problems passing a variable to from one subroutine to another. I have declared them public, yet it doesn't seem to work. It says subroutine out of range. All I need is to use varUnique (an array) and firstIndex on my second subroutine. What do I need to do to accomplish this?</p>
  
  <pre><code>Public fistIndex As Integer
  Public varUnique As Variant
  Sub FindUnique()
  
      Dim varIn As Variant
      Dim iInCol As Long
      Dim iInRow As Long
      Dim iUnique As Long
      Dim nUnique As Long
      Dim isUnique As Boolean
      Dim lastIndex As Integer
  
      varIn = Range("List")
      ReDim varUnique(1 To UBound(varIn, 1) * UBound(varIn, 2))
  
      nUnique = 0
      For iInRow = LBound(varIn, 1) To UBound(varIn, 1)
          For iInCol = LBound(varIn, 2) To UBound(varIn, 2)
  
              isUnique = True
              For iUnique = 1 To nUnique
                  If varIn(iInRow, iInCol) = varUnique(iUnique) Then
                      isUnique = False
                      Exit For
                  End If
              Next iUnique
  
              If isUnique = True Then
                  nUnique = nUnique + 1
                  varUnique(nUnique) = varIn(iInRow, iInCol)
              End If
  
          Next iInCol
      Next iInRow
      '// varUnique now contains only the unique values.
      '// Trim off the empty elements:
      ReDim Preserve varUnique(1 To nUnique)
      firstIndex = LBound(varUnique)
      lastIndex = UBound(varUnique)
  
  
  create:
      If Not varUnique(firstIndex) = "Sub-Total" Then
      Worksheets.Add.Name = varUnique(firstIndex)
      Call Ledge(varUnique, firstIndex)
      Else
      End
      End If
      If Not firstIndex = lastIndex Then
      firstIndex = firstIndex + 1
      ActiveCell.Offset(1, 0).Select
      GoTo create
      Else
      End If
  End Sub
  Sub Ledge(varUnique, firstIndex)
  '
  
  '
  
  'Define Variables
  Dim Account_type As String
  Dim Debit As Long
  Dim Credit As Long
  
  
  'Select Journal and Cell B4
      Sheets("Journal").Select
      Range("B4").Select
  
  Account_Search:
  'Make that cell= account_type
      Account_type = ActiveCell.Value
  'If that cell= cash then save the values adjecent
      If Account_type = varUnique(firstIndex) Then
          ActiveCell.Offset(0, 1).Select
          Debit = ActiveCell.Value
          ActiveCell.Offset(0, 1).Select
          Credit = ActiveCell.Value
  'Then go back to where you began
          ActiveCell.Offset(0, -2).Select
  'Select Cash and Cell A2
          Sheets(varUnique(firstIndex)).Select
          Range("A2").Select
  Search:
  'If both cells are empy
              If ActiveCell.Value = "" And ActiveCell.Offset(0, 1).Value = "" Then
  'Then write values and indicate you have done so
                 ActiveCell.Value = Debit
                 ActiveCell.Offset(0, 1).Select
                 ActiveCell.Value = Credit
                 Else
  'If they are not empty go down one cell and search again
                 ActiveCell.Offset(1, 0).Select
                 GoTo Search
              End If
  'Once it is recorded go to Journal again and go down one more cell
                  Sheets("Journal").Select
                  ActiveCell.Offset(1, 0).Select
  'If it wasn't cash then go down one
      Else
          ActiveCell.Offset(1, 0).Select
      End If
  'Record that cell value and check to see if it is not sub-total
      Account_type = ActiveCell.Value
      If Not Account_type = "Sub-Total" Then
  'Now see if it is cash
          GoTo Account_Search
      Else
      End If
  End Sub
  </code></pre>