Adding Borders with VBA

riedyp

Board Regular
Joined
Feb 13, 2020
Messages
88
Office Version
  1. 365
Platform
  1. Windows
Hello,
I am trying to add a button that will edit the row under the last row with values. I am having difficulty with adding a border around Cell (SubNewRow,2).
Also, if i wanted to span this border on SubNewrow from column B to M how would I write that?
Thanks.
VBA Code:
Private Sub CommandButton2_Click() 'If YES
SubNewRow = Sheet5.Cells(1000, 2).End(xlUp).Row + 1      'Finds the last edited row and then adds 1 row
Sheet5.Rows(SubNewRow).RowHeight = 18.6
Sheet5.Range("B" & SubNewRow).Resize(, 8).MergeCells = True
Sheet5.Range("M" & SubNewRow).Resize(, 3).MergeCells = True
Sheet5.Cells(SubNewRow, 2).Value = "If YES:"
Sheet5.Cells(SubNewRow, 2).Font.Bold = True
'''Border
Sheet5.Range(SubNewRow, 2).BorderAround.Weight = xlThin
    
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
How about
VBA Code:
Sheet5.Cells(SubNewRow, 2).Resize(, 12).BorderAround , xlThin
 
Upvote 0
Thank you. And for that range, is there a "BorderAll" or "BorderInside" command? Essentially making a border for all borders within the range or just the inside cells?
 
Upvote 0
How about
VBA Code:
With Sheet5.Cells(SubNewRow, 2).Resize(, 12)
   .BorderAround , xlThin
   .borders(xlInsideVertical).Weight = xlThin
End With
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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