Draw Borders around a Row to Last Colulmn used

johndrew

Board Regular
Joined
Apr 21, 2007
Messages
100
I would like to draw a Bold border around a Range from B2 to the last column used.
Also around the last Column down till the last row used.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Assuming that you meant using code try the sample below in a standard module.

Hope it helps.

Gary

Code:
Public Sub Test()

Dim lLastRow As Long
Dim lLastCol As Long
Dim oTarget As Range

lLastRow = ActiveSheet.Cells.Find(what:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
lLastCol = ActiveSheet.Cells.Find(what:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column

Set oTarget = ActiveSheet.Range("B2:" & ActiveSheet.Cells(lLastRow, lLastCol).Address)

With oTarget.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .Weight = xlThick
    .ColorIndex = xlAutomatic
End With
With oTarget.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .Weight = xlThick
    .ColorIndex = xlAutomatic
End With
With oTarget.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlThick
    .ColorIndex = xlAutomatic
End With
With oTarget.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .Weight = xlThick
    .ColorIndex = xlAutomatic
End With

End Sub
 
Upvote 0
I just need borders around the one row (row2) It now goes up and gets b1 and draws borders around the entire range.
 
Upvote 0
I just need borders around the one row (row2) It now goes up and gets b1 and draws borders around the entire range.

Does this do what you want...

Code:
Sub BorderAroundFirstRowLastColumn()
  Dim LastRow As Long, LastCol As Long
  LastRow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, _
            SearchDirection:=xlPrevious, LookIn:=xlValues).Row
  LastCol = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlByColumns, _
            SearchDirection:=xlPrevious, LookIn:=xlValues).Column
  Range(Cells(2, 2), Cells(2, LastCol)).BorderAround xlContinuous, xlThick
  Range(Cells(2, LastCol), Cells(LastRow, LastCol)).BorderAround xlContinuous, xlThick
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top