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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
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,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

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