title: Excel VBA add border if active cell on certain row
body: <p>I am writing some VBA for a Gantt Chart spreadsheet.</p>
  
  <p>I have 3 months worth of dates on row 5 and i can set the start date by entering a date in a cell which updates the whole sheet.</p>
  
  <p>I have a range of cells for my chart L6:CZ42.  For this range, if the cell in row 5 is the 1st of the month, every cell in that column will have a grey dotted left border and nothing on the right.  This works how i want it to.</p>
  
  <p>The problem is that it adds a grey border to the top and bottom of the cell which is OK for rows 7 to 41, but with row 6 i want a black top border and for row 42 I want a black bottom border.</p>
  
  <p>I added this section of code trying to sort this problem but the syntax is wrong checking if it's on row 6</p>
  
  <pre><code>' If this is the first row (6) in the range then
  ' add a black continuous border to the top
  If Cells(6, i) Then
      With .Borders(xlEdgeTop)
          .ColorIndex = 1
          .Weight = xlThin
          .LineStyle = xlContinuos
      End With
  End If
  </code></pre>
  
  <p>This is my whole code </p>
  
  <pre><code>Sub Worksheet_Change(ByVal Target As Range)
  
  Dim i As Long
  Dim CuDate As Date
  
  
  For i = 12 To 104
  CuDate = Cells(5, i).Value
  
  ' Are we on the 1st day of the month
  If Day(CuDate) = 1 Then
      With Range(Cells(6, i), Cells(42, i))
          ' If this is the first row (6) in the range then
          ' add a black continuous border to the top
          If Cells(6, i) Then
              With .Borders(xlEdgeTop)
                  .ColorIndex = 1
                  .Weight = xlThin
                  .LineStyle = xlContinuos
              End With
          End If
  
          With .Borders(xlEdgeLeft)
              .ColorIndex = 15
              .Weight = xlThin
              .LineStyle = xlDot
          End With
          With .Borders(xlEdgeRight)
              .LineStyle = xlLineStyleNone
          End With
      End With
  Else
      With Range(Cells(6, i), Cells(42, i))
          ' If this is the last row (42) in the range then
          ' add a black continuous border to the bottom
          If Cells(42, i) Then
              With .Borders(xlEdgeBottom)
                  .ColorIndex = 1
                  .Weight = xlThin
                  .LineStyle = xlContinuos
              End With
          End If
  
          With .Borders(xlEdgeLeft)
              .LineStyle = xlLineStyleNone
          End With
          With .Borders(xlEdgeRight)
              .LineStyle = xlLineStyleNone
          End With
      End With
  End If
  
  Next
  End Sub
  </code></pre>