VBA Border around range if row contains any data - Auto update

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
840
Hello,

I'd like some VBA worksheet change to apply borders that applies to a range when data is entered.

So, For examples data is in B12:AB700.

But at present data is only up to row 125 so should only apply to this.

Any ideas? Thanks.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I'm not sure we have enough information, but if the last row used can be determined from column B and the last column can be determined from row 12, then you could try this in a copy of your workbook.

If it is not what you want, please give more details about what you have, what you are doing with the sheet and what you are trying to achieve.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rMax As Range
  
  Set rMax = Intersect(Rows("12:" & Rows.Count), Columns("B").Resize(, Columns.Count - 1))
  If Not Intersect(Target, rMax) Is Nothing Then
    rMax.Borders.LineStyle = xlNone
    Range("B12", Range("B" & Rows.Count).End(xlUp)).Resize(, Cells(12, Columns.Count).End(xlToLeft).Column - 1).BorderAround LineStyle:=xlContinuous
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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