Formatting borders for a column until last row of data

VBAExpertWannabe

New Member
Joined
Jan 8, 2020
Messages
10
Office Version
  1. 2019
Platform
  1. Windows
I want to apply borders to the right edge for Column H of my data, starting from J:20 onto the last row of data (there are several rows of empty data in between). I have the following code but somehow, it is not working. Can anybody see what I did wrong? Thanks.

Sub Border()

Range("J" & Rows.Count).End(xlUp).Borders(xlEdgeRight).LineStyle = xlContinuous

End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try using
VBA Code:
Range("J20:J" & Rows.Count).End(xlUp).Borders(xlEdgeRight).LineStyle = xlContinuous
 
Upvote 0
Try then
VBA Code:
Range("J20:J" & (Cells(Rows.Count, "J").End(xlUp).Row)).Borders(xlEdgeRight).LineStyle = xlContinuous
 
Upvote 0
Try then
VBA Code:
Range("J20:J" & (Cells(Rows.Count, "J").End(xlUp).Row)).Borders(xlEdgeRight).LineStyle = xlContinuous

That worked PERFECTLY - thank you so much!!!

p.s. how can we learn more about these solutions?? There's no way I would have gotten that answer on my own.
 
Upvote 0
Practice, practice and practice....read the forum and look at solutions provided....then try modifying the solution to try and different results....
 
Upvote 0
Thank you. And just to follow up - I want to apply a single underline to rows, starting from Column C to Column J, there are several empty data in between as well. I don't think I want to specify which rows to underline (for now) but just the rows that I am at. How do I adjust my formula so it goes all the way to the 'last available column with data'?

Range(Selection, Selection.End(xlToRight)).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
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
 
Upvote 0
Try using this goes from C1 to the lastrow in "J"
Also, in future please use code tags when posting code.....Paste the code into the reply window, highlight the code, then press the < vba > button on the toolbar
VBA Code:
Sub MM1()
Dim lr As Long
lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
With Range("C1:J" & lr).Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlThin
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top