Automatically change the range of the Macro Formula when i insert column or row
Hello excel forum.. is it possible to automatically change the range of the formula in my macro code ?
For example: i create a code in my sheet 1. get the sum in H1:H10 the result is in H11.. and when i try to insert a row or column Between my the range i set
it will automatically change the range ?
like when you create a formula not using the macro.. when you add other column or row in the range of the formula. the formula will adjust..
is it possible ? anybody can help me..
sorry for my grammar if you don' understand.. i wish anybody here can help me.. Thanks GOD Bless..
Here's the code
'Set a Formula in sheet.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Range("H1:H500")) Is Nothing Then
If Target.Address <> "$H$11" Then
Application.EnableEvents = False
Range("H11").Formula = "=SUM(H1:H10)"
Application.EnableEvents = True
End If
End If
If Not Intersect(Target, Range("F1:F500")) Is Nothing Then
If Target.Address <> "$F$11" Then
Application.EnableEvents = False
Range("F11").Formula = "=SUM(F1:F10)"
Application.EnableEvents = True
End If
End If
End Sub
Bookmarks