I have an Excel (365) spreadsheet that Column A and Column B have no data as they will be filled in by a Vendor after we send it to them. My last Column in the Spreadsheet is Column O and I would like to apply borders to all cells in the used range but my code applies borders past the used range in Columns A through O because there is no data for Columns A & B.
I am editing some code I found and am close but no cigar yet.
Sub TestBorder()
Dim iRange As Range
Dim LastRow as Integer
LastRow = Cells(Rows.Count, 3).End(xlUp).Row
With ActiveSheet
Set iRange = .UsedRange.Cells(.UsedRange.Cells.Count)
With .Range("A:O"), iRange).Borders
Set iRange = ActiveWorkbook.Worksheets("Sheet1").UsedRange.Offset(1, 1)
.LineStyle = xlContinuous
.Weight = xlThin
End With
End With
End If
End Sub
>Solution :
Option Explicit
Sub TestBorder()
Dim LastRow As Integer
With ActiveSheet
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
With .Range("A1:O" & LastRow).Borders()
.LineStyle = xlContinuous
.Weight = xlThin
End With
End With
End Sub