Share via

create borders using vba

Anonymous
2010-09-14T06:21:57+00:00

hi all,

using macro, i want to create borders from col A - col Y, and for rows it depend with last cell in col A.

i.e.

if col A have values till A1300, then it will create borders from A1:Y1300.

if col A have values till A50, then it will create borders from A1:Y50.

hope you get with i want

many thanks


Regards, Rasyha

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-09-14T09:25:43+00:00

If the requirment is for Borderaround; that could be acheived using BorderAround

With Range("A1", Cells(Cells(Rows.Count, "A").End(xlUp).Row, "Y"))

  .Borders.LineStyle = xlNone

  .BorderAround xlContinuous, xlThin, xlColorIndexAutomatic

End With

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Anonymous
2010-09-14T07:36:40+00:00

If the region around which you want to put the border contains no blank rows or blank columns but column Z is blank then

With Range("A1").CurrentRegion

  .Borders.LineStyle = xlNone  ' clear current borders 

  With .Borders(xlEdgeLeft)

    .LineStyle = xlContinuous

    .Weight = xlThin

    .ColorIndex = xlAutomatic

  End With

  With .Borders(xlEdgeTop)

    .LineStyle = xlContinuous

    .Weight = xlThin

    .ColorIndex = xlAutomatic

  End With

  With .Borders(xlEdgeBottom)

    .LineStyle = xlContinuous

    .Weight = xlThin

    .ColorIndex = xlAutomatic

  End With

  With .Borders(xlEdgeRight)

    .LineStyle = xlContinuous

    .Weight = xlThin

    .ColorIndex = xlAutomatic

  End With

End With


if the assumptions I made are not valid then replace the first line with

  With Range("A1",Cells(Cells(Rows.Count,"A").End(xlUp).Row, "Y"))


Bill Manville. Excel MVP, Oxford, England. www.manville.org.uk

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2010-09-14T13:04:55+00:00

    Nice one, Jackpot.

    I forgot that useful BorderAround method.

    Much more succinct than the code the macro recorder gave me!


    Bill Manville. Excel MVP, Oxford, England. www.manville.org.uk

    Was this answer helpful?

    0 comments No comments