border round a table

methody

Well-known Member
Joined
Jun 17, 2002
Messages
857
Hello I have a range of cells - a sports league table - with formulas in it from AW6 to BF50.
The cells in AW are linked to another part of the sheet where teams are input. The formula in AW6 is IF(AG6="","",AG6)) - So teams are entered in AG6 and below
If there is one team, AW6 will not be "" and all the cells across will not be "".
If there are two teams, AW6 & AW7 will not be "" and all the cells across will not be "". etc

So the number of teams in the AW column determines the height of the table.

I am looking for a piece of code which will put a simple border round the sides and bottom of the table.
So as you go down AW. At the point where you first find "", put a border along the bottom and up the side.

I would prefer code as opposed to conditional formatting if possible.
thank you
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
Set c = Intersect(Target, Range("AW6:AW50"))
If c Is Nothing Then Exit Sub
With c.Resize(, 10)
    .Borders.LineStyle = xlNone
    .BorderAround xlSolid, xlThin
    .Borders(xlEdgeTop).LineStyle = xlNone
End With
End Sub
 
Upvote 0
Hello Hotpepper
Thank you for that.
It does what I asked although I am trying to simply fit it onto to another macro as opposed to that worksheet event. Do I need to change this line?
Set c = Intersect(Target, Range("AW6:AW50"))

thank you
 
Upvote 0
Code:
Sub test()
Dim x As Long
x = Range("AW50").End(xlUp).Row
If x < 6 Then x = 6
With Range("AW" & x).Resize(, 10)
    .Borders.LineStyle = xlNone
    .BorderAround xlSolid, xlThin
    .Borders(xlEdgeTop).LineStyle = xlNone
End With
End Sub
 
Upvote 0
Hello Hotpepper
sorry but this doesn't seem to work . It continually seems to treat the table as if it has one non empty row now matter how many teams there are.

thanks
 
Upvote 0
I think it works if the cells in AW are completely empty but not if they have formula which give "".
 
Upvote 0
Then all you need to do is base the end on that range:

Code:
Sub test()
Dim x As Long
x = Range("AG50").End(xlUp).Row
If x < 6 Then x = 6
With Range("AW" & x).Resize(, 10)
    .Borders.LineStyle = xlNone
    .BorderAround xlSolid, xlThin
    .Borders(xlEdgeTop).LineStyle = xlNone
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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