![]() |
Macro formatting last row
I tried posting this question earlier and received an error message, so I
apologize if this question shows up twice. I'm trying to insert a bottom border on a range of cells, but I can't figure out the syntax for the range. Here's what I currently have: Range("B" & lastrow).Select With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With This works for column B, but I want the border to also be on column C and D. I could add the same code for each column separately, but I'm wondering if there is a way to do the entire range (B:D) at one time. Thanks! |
Macro formatting last row
You don't need to select the range first:
with Range("B" & lastrow).Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With And you can resize that range, too: with Range("B" & lastrow).resize(1,3).Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With ..resize(1,3) means make that range 1 row by 3 columns. Erin wrote: I tried posting this question earlier and received an error message, so I apologize if this question shows up twice. I'm trying to insert a bottom border on a range of cells, but I can't figure out the syntax for the range. Here's what I currently have: Range("B" & lastrow).Select With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With This works for column B, but I want the border to also be on column C and D. I could add the same code for each column separately, but I'm wondering if there is a way to do the entire range (B:D) at one time. Thanks! -- Dave Peterson |
Macro formatting last row
Just resize it:
Sub dural() lastrow = Cells(Rows.Count, "B").End(xlUp).Row Range("B" & lastrow).Resize(1, 3).Select With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With End Sub -- Gary''s Student - gsnu201001 "Erin" wrote: I tried posting this question earlier and received an error message, so I apologize if this question shows up twice. I'm trying to insert a bottom border on a range of cells, but I can't figure out the syntax for the range. Here's what I currently have: Range("B" & lastrow).Select With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With This works for column B, but I want the border to also be on column C and D. I could add the same code for each column separately, but I'm wondering if there is a way to do the entire range (B:D) at one time. Thanks! |
Macro formatting last row
Brilliant! That did it -- thanks so much :-)
"Gary''s Student" wrote: Just resize it: Sub dural() lastrow = Cells(Rows.Count, "B").End(xlUp).Row Range("B" & lastrow).Resize(1, 3).Select With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With End Sub -- Gary''s Student - gsnu201001 "Erin" wrote: I tried posting this question earlier and received an error message, so I apologize if this question shows up twice. I'm trying to insert a bottom border on a range of cells, but I can't figure out the syntax for the range. Here's what I currently have: Range("B" & lastrow).Select With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = xlAutomatic End With This works for column B, but I want the border to also be on column C and D. I could add the same code for each column separately, but I'm wondering if there is a way to do the entire range (B:D) at one time. Thanks! |
All times are GMT +1. The time now is 11:02 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com