P.Olsa
P.Olsa

Reputation: 7

Row border end at specific column

I have question about VBA in Excel. I have border generated for each row, but I need to end border on specific column. I tryed to find solution for this, but nothing which will solve my problem.

ActiveWorkbook.Sheets(C_CI_LIST).Range(C_CI_COL_CATEGORY & endOfCIHeader + 1).EntireRow.Insert
            With ActiveWorkbook.Sheets(C_CI_LIST).Range(C_CI_COL_CATEGORY & endOfCIHeader + 1).EntireRow
                            .Borders(xlEdgeTop).LineStyle = xlContinuous
                            .Borders(xlEdgeTop).Weight = xlThin
                        End With 

This will generate me border for each row as I want, but I need have border for entire row and stop border at Column "AD", I tryed to change Range in many ways, but nothing helps. Do you have any suggestions?

Upvotes: 0

Views: 111

Answers (1)

Pᴇʜ
Pᴇʜ

Reputation: 57683

Because you apply the borader to the .EntireRow it of course formats the border of the entire row.

Instead you need to apply it to a specific range only. For example

Range("A1").EntireRow.Borders(xlEdgeTop) 

will format the border of the entire row 1, but

Range("A1", "Z1").Borders(xlEdgeTop)

will format the border of row 1 from column A to Z only. Alternativeley as @JvdV mentioned in the comment you can use

Range("A1").Resize(ColumnSize:=30).Borders(xlEdgeTop) 

to format 30 columns of row 1 starting from column A.

Upvotes: 1

Related Questions