Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bordering in Excel using VB

Status
Not open for further replies.

ahbyun

Technical User
Dec 11, 2004
9
0
0
KR
I thought it would work but for some reason it doesn't.
What I'm trying to do is add borders around every cell from Columns 1 to 11 and Rows 1 to Seq=71
It does work except it only draws the border on every other cell instead of every cell.

Any suggestions???

Thank you


I have the following code:
For C2 = 1 To 11
For R2 = 1 To Seq

Cells(R2, C2).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

R2 = R2 + 1

Next

C2 = C2 + 1

Next




 
ahbyun,

The root cause of you problem is in the lines

R2 = R2 + 1

and

C2 = C2 + 1

they are not required, simply rem them.

I think however the code can be reduced to;

For C2 = 1 To 11
For R2 = 1 To Seq
With Cells(R2, C2).Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Next
Next

regards Hugh

 
Or even:

With Range("A1:K71").Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

For tsunami relief donations

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top