0

Everyday I run a list, it is always different. It will have different amounts of rows with different values in them every day.

List 1 List 2

I have coded it so I have horizontal borders exactly as I want, but now I need the vertical (side - left and right) borders. I would like thin borders in every cell that contains text or a value of some kind, in every column and every row after including row 1. Again, the amount of rows and columns will vary every day, so it's important that the code can account for that.

Option Explicit
Sub Borders()
    Dim WS As Worksheet
    Dim dataRange As Range
    Dim v As Variant, I As Long

Set WS = ActiveWorkbook.Worksheets("Sheet1")

With WS
    Set dataRange = Range(.Cells(2, 1), Cells(.Rows.Count, 10).End(xlUp))
    Set dataRange = dataRange.Resize(rowsize:=dataRange.Rows.Count + 1)
    With dataRange
        v = .Columns(10)
        For I = 1 To UBound(v) - 1
            If v(I, 1) <> v(I + 1, 1) Then
                With .Rows(I).Borders(xlEdgeBottom)
                    .LineStyle = xlContinuous
                    .Color = vbBlack
                    .Weight = xlMedium
                 End With
            Else
                .Rows(I).Borders(xlEdgeBottom).LineStyle = 1 'Default Border
            End If
        Next I
    End With
End With

'This is where I'd like the code for the vertical borders to go

End Sub

I would like the end product to look like this. Final Product

1 Answer 1

1

This sets vertical borders for all cells in the usedrange after row 1.

'Sets vertical borders
Dim iRange As Range
Dim iCells As Range

Set iRange = ActiveWorkbook.Worksheets("Sheet1").UsedRange.Offset(1, 1)

For Each iCells In iRange
    If Not IsEmpty(iCells) Then
        With iCells.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlThin
        End With
        With iCells.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlThin
        End With
    End If
Next iCells

You must log in to answer this question.