Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Apply Borders to Used Range when First Column has no data

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading