title: Scope of Cell Object in For Loop - VBA
body: <p>I'm working on a bit of VBA that's intended to loop over a Schedule Builder for students made in Excel. I keep getting an Error 424 during the assignments <code>c = c.Offset(X, 0)</code>, but only in the nested For loops. Is there a limited scope, and if so, how do I overcome it?</p>
  
  <p>Below is the code:</p>
  
  <pre><code>    Public Sub generateRosters()
  
      Worksheets("Course Rosters").Cells.ClearContents
      Worksheets("Course Rosters").Range("A1") = "Course"
      Worksheets("Course Rosters").Range("B1") = "Room"
  
      Dim classTitleRange As Range
      Set classTitleRange = Worksheets("Master School Schedule").Range("D1:BN1")
  
      Dim rowCount As Integer
      rowCount = 2
  
      Dim periodArr(1 To 8) As String
      periodArr(1) = "A"
      periodArr(2) = "B"
      periodArr(3) = "C"
      periodArr(4) = "D"
      periodArr(5) = "E"
      periodArr(6) = "F"
      periodArr(7) = "G"
      periodArr(8) = "Z"
  
      For Each c In classTitleRange.Cells
  
          Dim courseTitle As String
          courseTitle = c
  
          c = c.Offset(2, 0)
  
          Dim room As String
          room = c
  
          For Each p In periodArr()
  
              Dim offsetCount As Integer
              offsetCount = 0
  
              For i = 1 To 340
                  c = c.Offset(1, 0) '424 Error One
                  If c = p Then
  
                  End If
                  offsetCount = offsetCount + 1
              Next
  
              c = c.Offset(-offsetCount, 0) '424 Error Two
  
          Next
  
          Worksheets("Course Rosters").Range("A" &amp; rowCount) = "'" &amp; courseTitle
          Worksheets("Course Rosters").Range("B" &amp; rowCount) = room
  
          rowCount = rowCount + 1
  
      Next
  
      End Sub
  </code></pre>
  
  <p>Thanks, for your help.</p>
  
  <p>Edit: Side question, is there a way for me to create a variable that I can manipulate like c, but not be c. Basically a <code>Dim d As (Something)</code> followed by <code>d = c</code>. I can't seem to find the right object to assign to d, so that I can make it c. Thanks again.</p>