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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Macro: Bottom border for each row not working

Status
Not open for further replies.

gdev

Technical User
Mar 12, 2001
38
0
0
Please Assist

I would like a bottom border For each row on the sheet from columns a:l
For some reason this code does not work.
What am I missing?

Dim x As Integer
Dim lastrow As Long

lastrow = Range("A65536").End(xlUp).Row

For x = 7 To lastrow
ActiveCell.Columns("A:L").Select

Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone

With Selection.Borders(xlEdgeBottom)

.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone

next x


Thanks
 




Hi,

Turn on your macro recorder, Select ALL the rows and columns you want formatted, Format > Cells > Borders

Set the INSIDE HORIZONTAL and BOTTOM borders.

Skip,
[sub]
[glasses] To be safe on the [red]FOURTH[/red],
Don't take a [red]FIFTH[/red] on the [red]THIRD[/red]
Or you might not come [red]FORTH[/red] on the [red]FIFTH[/red]
[red][highlight blue]FORTH[/highlight][/red][white][highlight red]WITH[/highlight][/white] [tongue][/sub]
 
You kept erasing the bottom line of one row because the next iteration set the top line to none.

Try this:

Code:
Dim x As Integer
Dim lastrow As Long

x = 7
While ActiveSheet.Cells(x, 1).Value <> ""
    With ActiveSheet.Range(Cells(x, 1), Cells(x, 12))
        .Borders(xlDiagonalDown).LineStyle = xlNone
        .Borders(xlDiagonalUp).LineStyle = xlNone
        .Borders(xlEdgeLeft).LineStyle = xlNone
        .Borders(xlEdgeRight).LineStyle = xlNone
        .Borders(xlInsideVertical).LineStyle = xlNone
        With .Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
    End With
    x = x + 1
Wend

BD
 


bd,

You do not need to loop. It is inefficient.

Skip,
[sub]
[glasses] To be safe on the [red]FOURTH[/red],
Don't take a [red]FIFTH[/red] on the [red]THIRD[/red]
Or you might not come [red]FORTH[/red] on the [red]FIFTH[/red]
[red][highlight blue]FORTH[/highlight][/red][white][highlight red]WITH[/highlight][/white] [tongue][/sub]
 
Skip,

True. I was trying to mold his code to accomplish his goal. The best method would be to set the border for the entire range all at once.

BD
 




...and that was my suggestion.

Skip,
[sub]
[glasses] To be safe on the [red]FOURTH[/red],
Don't take a [red]FIFTH[/red] on the [red]THIRD[/red]
Or you might not come [red]FORTH[/red] on the [red]FIFTH[/red]
[red][highlight blue]FORTH[/highlight][/red][white][highlight red]WITH[/highlight][/white] [tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top