route217
asked on
Macro to add borders based on last row of data in column A
Hi Experts
I have the following VBA but is not running and or working can you kindly assist...
Dim lastrow as long
LastRow = Range("A1" & Row.Count).End(xlUp).Row
.Range("A1" & LastRow & ":AD" & LastRow).Borders(xlEdgeLef t).LineSty le = xlContinuous
.Range("A1" & LastRow & ":AD" & LastRow).Borders(xlEdgeRig ht).LineSt yle = xlContinuous
.Range("A1" & LastRow & ":AD" & LastRow).Borders(xlEdgeTop ).LineStyl e = xlContinuous
.Range("A1" & LastRow & ":AD" & LastRow).Borders(xlEdgeBot tom).LineS tyle = xlContinuos
.Range("A1" & LastRow & ":AD" & LastRow).Borders(xlInsideV ertical).L ineStyle = xlContinuous
.Range("A1" & LastRow & ":AD" & LastRow).Borders(xlInsideH orizontal) .LineStyle = xlContinuous
thanks
I have the following VBA but is not running and or working can you kindly assist...
Dim lastrow as long
LastRow = Range("A1" & Row.Count).End(xlUp).Row
.Range("A1" & LastRow & ":AD" & LastRow).Borders(xlEdgeLef
.Range("A1" & LastRow & ":AD" & LastRow).Borders(xlEdgeRig
.Range("A1" & LastRow & ":AD" & LastRow).Borders(xlEdgeTop
.Range("A1" & LastRow & ":AD" & LastRow).Borders(xlEdgeBot
.Range("A1" & LastRow & ":AD" & LastRow).Borders(xlInsideV
.Range("A1" & LastRow & ":AD" & LastRow).Borders(xlInsideH
thanks
or, this seems to work better:
Sub test()
Dim lastrow As Long
Dim myRange As Range
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set myRange = Range("A" & lastrow & ":AD" & lastrow)
With myRange.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With myRange.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With myRange.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With myRange.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With myRange.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With myRange.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
ASKER
Man thanks for the feedback
ASKER
Hi teylyn
I am getting a run error 1004 when using the first vba code you posted..
Thanks
.borders(xlinsidehoruzonta l).linesty le = xlcontinuous
I am getting a run error 1004 when using the first vba code you posted..
Thanks
.borders(xlinsidehoruzonta
What version of Excel? The object model is different after 2003. The code I posted will work for 2007 and above.
Please note that XL 2003 has been out of support for more than two years. If you are not using the current XL version, please state your version in your question.
Please note that XL 2003 has been out of support for more than two years. If you are not using the current XL version, please state your version in your question.
ASKER
Apologies for excel 2003...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you're after formatting only one row, then you can simply delete the last "With" block in the macro posted in comment #37860204. Delete this bit:
With myRange.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
try
Open in new window
cheers, teylyn