Dark0Prince
Active Member
- Joined
- Feb 17, 2016
- Messages
- 433
This code should keep adding up when i type in certain columns if the words Grand Totals or Totals aren't there. But doesn't seem to work anymore.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myrange As Range
Dim c As Range
Dim myArray As Variant
Dim a As Long
Dim skip As Boolean
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub '<= moved up
myArray = Array("Grand Totals", "TOTALS") 'adjust data as needed
Application.EnableEvents = False
Set myrange = Intersect(Target, Range("M6:M2000")) '<- adjust range as needed
If Not myrange Is Nothing Then
For Each c In myrange
For a = 0 To UBound(myArray)
If Cells(c.Row, 2) = myArray(a) Then skip = True 'test cell in column B
Next a
If skip = False Then Cells(c.Row, 15).Value = Cells(c.Row, 15).Value + c
Next c
End If
Set myrange = Intersect(Target, Range("N6:N2000")) '<- adjust range as needed
If Not myrange Is Nothing Then
For Each c In myrange
For a = 0 To UBound(myArray)
If Cells(c.Row, 2) = myArray(a) Then skip = True 'test cell in column B
Next a
If skip = False Then Cells(c.Row, 16).Value = Cells(c.Row, 16).Value + c
Next c
End If
If Not Intersect(Target, Range("M6:M2000")) Is Nothing Then '<- adjust range as needed for auto date
Columns("O").AutoFit
End If
Application.EnableEvents = True '<= moved down
Set myrange = Intersect(Target, Range("T6:T2000")) '<- adjust range as needed
If Not myrange Is Nothing Then
For Each c In myrange
For a = 0 To UBound(myArray)
If Cells(c.Row, 2) = myArray(a) Then skip = True 'test cell in column B
Next a
If skip = False Then Cells(c.Row, 21).Value = Cells(c.Row, 21).Value + c
Next c
End If
Set myrange = Intersect(Target, Range("V6:V2000")) '<- adjust range as needed
If Not myrange Is Nothing Then
For Each c In myrange
For a = 0 To UBound(myArray)
If Cells(c.Row, 2) = myArray(a) Then skip = True 'test cell in column B
Next a
If skip = False Then Cells(c.Row, 23).Value = Cells(c.Row, 23).Value + c
Next c
End If
If Not Intersect(Target, Range("M6:M2000")) Is Nothing Then '<- adjust range as needed for auto date
Columns("Q").AutoFit
End If
Application.EnableEvents = True '<= moved down
Set myrange = Intersect(Target, Range("X6:X2000")) '<- adjust range as needed
If Not myrange Is Nothing Then
For Each c In myrange
For a = 0 To UBound(myArray)
If Cells(c.Row, 2) = myArray(a) Then skip = True 'test cell in column B
Next a
If skip = False Then Cells(c.Row, 25).Value = Cells(c.Row, 25).Value + c
Next c
End If
If Not Intersect(Target, Range("M6:M2000")) Is Nothing Then '<- adjust range as needed for auto date
Columns("Q").AutoFit
End If
End Sub