title: Subscript out of Range when choosing a Workbook
body: <p>When I tried to get excel to  choose which workbook to use, it gives me an error for subscript out of range. I don't know whether I have to reference which folder it originates from. They are all in the same folder. I looked through other peoples solutions,but I don't have neither the same format nor task. The error is  on the line where it assigns workbook numbers</p>
  
  <pre><code>Sub bringbookstogether()
  
  Dim currentsheet As Worksheet
  Set currentsheet = Application.ActiveSheet
  
  Dim othersheets As Worksheet
  
  Dim wbook As Workbook
  
  Dim c As String
  
  'assigns the number to start with
  
  Dim a, b, d As Integer
  
  a = 4
  b = 6
  d = 1
  
  'assigns workbook numbers
  If (d = 1) Then
      Set wbook = Workbooks("MaintPrep Sheet 1st")
      Else
      If (d = 2) Then
          Set wbook = Workbooks("MaintPrep Sheet 2nd")
          Else
          If (d = 3) Then
              Set wbook = Workbooks("MaintPrep Sheet 3rd")
          End If
      End If
  End If
  
  'End if it's done with all the workbooks
  
  Do Until (d = 4)
  
  'Looks for the sheet that has the same name
  
  Do While (c = currentsheet.Name)
  
  'Ends in row 99
  
  Do While (b &lt; 99)
  
  'Ends in Column 52
  
  Do While (a &lt; 52)
  
  currentsheet.Cells(b, a) = currentsheet.Cells(b, a) + Workbooks(d).Sheets(c).Cells(b, a)
  
  a = a + 1
  Loop
  
  b = b + 1
  Loop
  
  Loop
  
  d = d + 1
  Loop
  
  End Sub
  </code></pre>