Format Fill Down to Last Row

G

Guest

I know it is possible for formulas, etc, but is it possible to have a macro
that formats a column of cells and only formats down to the last row? It
will always be the same column, but there will be a different number of rows
each time.
 
G

Guest

Format: The diagonal line going through the cell (lower left to upper right)
Row: The last row that is populated (remember, this will change everytime I
run the macro)
Column: D

In other words:
Selection.Borders(xlDiagonalDown).Linestyle=xlNone
With selection.borders(xlDiagonalup)
.Linestyle=xlContinuous
.Weight=xlHairline
..ColorIndex=xlAutomatic
....
 
G

Guest

hi
this should work. try it and post back if problems.
sub addformats()
Dim r As Long
lr = cells(Rows.Count, "D").End(xlUp).Row
Range("D1:D" & lr).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
With Selection.Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub

Regards
FSt1
 
G

Gord Dibben

Sub Auto_Format()
Dim Lrow As Long
With ActiveSheet
Columns(3).Cells.Interior.ColorIndex = xlNone
Lrow = Range("C" & Rows.Count).End(xlUp).Row
Range("C1:C" & Lrow).Interior.ColorIndex = 3
End With
End Sub


Gord Dibben MS Excel MVP
 
G

Gord Dibben

I would add one line to clear the borders from the previous range.

Otherwise they will remain if number of rows is less than previous.

Sub addformats()
Dim r As Long
lr = Cells(Rows.Count, "D").End(xlUp).Row
Columns("D").Borders(xlDiagonalUp).LineStyle = xlNone 'add this line
Range("D1:D" & lr).Select
'this line not needed Selection.Borders(xlDiagonalDown).LineStyle = xlNone
With Selection.Borders(xlDiagonalUp)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub


Gord
 

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