Excel should allow you to create borders around columns easier

G

Guest

Excel provides a number of options for creating borders around selected
cells, but does not do a good job at allowing you to automatically format
colums with borders. For example, if are working with Columns A-B-C and rows
2-10 and want to put a border around each column (A2-A10, B2-B10, and
C2-C10), you have to select each column and select the "box" border. What
would be great is if there was a button that you could push that would do
this for you, like when you select a group of cells and want every cell in
that group to have a border.

----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.

http://www.microsoft.com/office/com...f-b1317972e566&dg=microsoft.public.excel.misc
 
D

Don Guillett

How about

Sub doborders()
Selection.Borders.Weight = xlMedium 'Thick
End Sub
 
G

Guest

I ran your code but it puts a border around every cell. What I was looking
for was selecting a number of columns containing a number of cells, say a 10
by 10 block. I would like just the columns to have a border. Not every cell
within the column. Thanks for the suggestion though.
 
D

Don Guillett

OK. Try this

Sub ColumnBorders()
Dim rng As Range
Set rng = Selection 'Range("a1", "d10")
'MsgBox rng.Address
fr = rng.Cells(1).Row
'MsgBox "first row is " & fr
fc = rng.Cells(1).Column 'Range("a1").Address
'MsgBox "first column is " & fc
lr = Range(rng.Address). _
Cells(Range(rng.Address).Cells.Count).Row
'MsgBox "Last row is " & lr
lc = Range(rng.Address). _
Cells(Range(rng.Address).Cells.Count).Column
'MsgBox "last column is " & lc
numcols = lc - fc + 1
'MsgBox numcols
For i = fc To numcols - 1 + fc
Range(Cells(fr, i), Cells(lr, i)). _
BorderAround Weight:=xlMedium
'MsgBox i
Next i
Cells(fr, fc).Select
End Sub
 
G

Guest

OK...Your a genius. This is perfect. Thanks.

Don Guillett said:
OK. Try this

Sub ColumnBorders()
Dim rng As Range
Set rng = Selection 'Range("a1", "d10")
'MsgBox rng.Address
fr = rng.Cells(1).Row
'MsgBox "first row is " & fr
fc = rng.Cells(1).Column 'Range("a1").Address
'MsgBox "first column is " & fc
lr = Range(rng.Address). _
Cells(Range(rng.Address).Cells.Count).Row
'MsgBox "Last row is " & lr
lc = Range(rng.Address). _
Cells(Range(rng.Address).Cells.Count).Column
'MsgBox "last column is " & lc
numcols = lc - fc + 1
'MsgBox numcols
For i = fc To numcols - 1 + fc
Range(Cells(fr, i), Cells(lr, i)). _
BorderAround Weight:=xlMedium
'MsgBox i
Next i
Cells(fr, fc).Select
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top