title: VBA and Excel, I am unsure how to run the method in my class on a certain sheet
body: <p>I have press alt + f11, gone into the code behind and written this:</p>
  
  <pre><code>Class style
      Public Sub IterateThroughData()
          Dim rowIndex As Integer
          Dim colIndex As Integer
          Dim rowOffset As Integer
          rowOffset = 6
          colIndex = 1
  
          For rowIndex = rowOffset To 15
              Dim currentDate As Date
              Dim nextRowDate As Date
              currentDate = Cells(rowOffset, colIndex).Value
              nextRowDate = Cells(rowIndex + 1, colIndex).Value
  
              If currentDate &lt;&gt; nextRowDate Then
                  RenderYearStyle(rowIndex,colIndex)
              End If
  
              currentDate = Cells(rowIndex, colIndex).Value
          Next rowIndex
      End Sub
  
      Private Sub RenderYearStyle(rowIndex As Integer, colIndex As Integer)
          With Cells(rowIndex, colIndex)
              .Borders(xlEdgeBottom).Weight = xlThin
              .Borders(xlInsideHorizontal).Weight = xlThin
          End With
      End Sub
  End Class
  
  Dim style As style
  Set style = New style
  style.IterateThroughData()
  </code></pre>
  
  <p>This should iterate through cells from row 6 column 1, to row 15 column 1.
  It will get the value of the current cell in the iteration and compare it to the next rows date.
  If they are not the same, then add a border to the bottom of that cell.</p>
  
  <p>It's a simple test but I am having problems, when I run it, it says invalid outside procedure. Any ideas?    </p>
  
  <p>I am assuming that I need to </p>
  
  <ol>
  <li>target a sheet on an excel file.</li>
  <li>have some sort of proper place to add the global scope declaration of my style class.</li>
  <li>correct any bugs in my code.</li>
  </ol>
  
  <p>EDIT:::</p>
  
  <p><strong>Class module</strong></p>
  
  <pre><code>Class style
      Public Sub IterateThroughData()
          Dim rowIndex As Integer
          Dim colIndex As Integer
          Dim rowOffset As Integer
          rowOffset = 6
          colIndex = 1
  
          For rowIndex = rowOffset To 15
              Dim currentDate As Date
              Dim nextRowDate As Date
              currentDate = Cells(rowOffset, colIndex).Value
              nextRowDate = Cells(rowIndex + 1, colIndex).Value
  
              If currentDate &lt;&gt; nextRowDate Then
                  RenderYearStyle(rowIndex,colIndex)
              End If
  
              currentDate = Cells(rowIndex, colIndex).Value
          Next rowIndex
      End Sub
  
      Private Sub RenderYearStyle(rowIndex As Integer, colIndex As Integer)
          With Cells(rowIndex, colIndex)
              .Borders(xlEdgeBottom).Weight = xlThin
              .Borders(xlInsideHorizontal).Weight = xlThin
          End With
      End Sub
  End Class
  
  Private Sub Class_Initialize()
      Dim MyStyles As style
      Set MyStyles = New style
  End Sub
  </code></pre>
  
  <p><strong>Workbook open</strong></p>
  
  <pre><code>Private Sub Workbook_Open()
      MyStyles.IterateThroughData()
  End Sub
  </code></pre>