Good Morning Everyone!
This is the first time I have ever attempted this sort of macro. I am more or less testing the logic to see if it works. The macro appears to be working, but I was wondering if anyone saw potential pitfalls in the code.
Eventually, I plan to add it to a worksheet so that when rows are inserted within a specified range it will be take the formulas from the above row and copy them down to the newly inserted row.
Here is the code, thanks in advance for taking a look!
This is the first time I have ever attempted this sort of macro. I am more or less testing the logic to see if it works. The macro appears to be working, but I was wondering if anyone saw potential pitfalls in the code.
Eventually, I plan to add it to a worksheet so that when rows are inserted within a specified range it will be take the formulas from the above row and copy them down to the newly inserted row.
Here is the code, thanks in advance for taking a look!
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim iFinalRow As Integer
iFinalRow = Cells(Rows.Count, 1).End(xlUp).Row
' Is target in desired range AND has the range expanded due to rows being inserted
If Not Application.Intersect(Target, Me.Range(Cells(5, 1), Cells(iFinalRow, 1))) Is Nothing And _
Target.CurrentRegion.End(xlDown).Row <> iFinalRow Then
' At least one cell of Target is within the range. Change above row color
Range("a1").Value = "Blue"
Else
' No cell of Target is in the range A5: Last row with data. Get Out.
Exit Sub
End If
End Sub