Поместите это позади объекта листа, на котором вы хотите запустить
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NoRows As Long
If Not Intersect(Target, Me.Range("D7")) Is Nothing Then
With Me
NoRows = .Range("D7").Value2
' Update with your reference to where the first row you want to change is
With .Range("A1").Resize(NoRows)
With .Borders
.Weight = xlThin
.LineStyle = xlContinuous
End With
End With
End With
End If
End Sub