title: Setting Left and Right cell borders at the same time in VBA
body: <p>Wondering if there's a way to set both the left and right borders of a cell with a single statement?  Something akin to the way <code>msgBox</code> configurations can be combined/added together (e.g. <code>vbYesNo + vbQuestion</code>).  I tried:</p>
  
  <pre><code>Cells(j, i).Borders(xlEdgeLeft + xlEdgeRight)
  </code></pre>
  
  <p>Which leads to an error for me.  It's a bit duplicative to code each border individually...</p>
  
  <p>Here what I've come up with:</p>
  
  <pre><code>For i = 1 To 10
      For j = 2 To 6 + numAcft
          Cells(j, i) = "Week Start Date"
          With Cells(j, i).Borders(xlEdgeLeft)
              .LineStyle = xlContinuous
              .Weight = xlMedium
          End With
          With Cells(j, i).Borders(xlEdgeRight)
              .LineStyle = xlContinuous
              .Weight = xlMedium
          End With
  ...
  ...
  </code></pre>
  
  <p>Is there a more elegant way?</p>
  
  <hr>
  
  <p>With full credit to @egan-wolf and @robinmackenzie here is the full solution I used to answer the above question.  As suggested I created a helper function and passed it the cell I want to set the borders for and the line style &amp; weight I'd like them to be, turning 8 lines of code into a much more readable single line: </p>
  
  <p><code>setLeftAndRightEdges Cells(j, i), xlContinuous, xlMedium</code></p>
  
  <pre><code>Private Sub setLeftAndRightEdges(ByVal cell As Range, ByVal lineStyle As Long, ByVal weight As Long)
        Dim edges(1) As Variant
        Dim edge As Variant
  
        edges(0) = xlEdgeLeft
        edges(1) = xlEdgeRight
  
        For Each edge In edges
              cell.Borders(edge).LineStyle = lineStyle
              cell.Borders(edge).weight = weight
        Next edge
  End Sub
  </code></pre>