I have written some VBA code which contains multiple worksheet change event triggers within a single sheet. It works as I would like it to however I find it has slowed my workbook down whenever I make any changes to it. I wondered if there is a more efficient way to write this code? See code below - the purpose is that if a user changes a cell value within a number of ranges, it concatenates the values from that range into another cell. Any advice would be much appreciated.
VBA Code:
Private Sub Worksheet_Change(ByVal target As Range)
Set myCell = Sheet5.Range("E13")
If Not Intersect(target, Range("X24:X28")) Is Nothing Then
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
Set rng = Range("X24:X28")
myCell.Value = ""
For Each Cell In rng
If Cell.Value <> "" Then
myCell.Value = myCell.Value & Cell.Value & vbNewLine
End If
Next
End If
If myCell.Value <> "" Then myCell.Value = Left(myCell.Value, Len(myCell.Value) - 1)
Set myCell = Sheet5.Range("E14")
If Not Intersect(target, Range("X35:X40")) Is Nothing Then
Set rng = Range("X35:X40")
myCell.Value = ""
For Each Cell In rng
If Cell.Value <> "" Then
myCell.Value = myCell.Value & Cell.Value & vbNewLine
End If
Next
End If
If myCell.Value <> "" Then myCell.Value = Left(myCell.Value, Len(myCell.Value) - 1)
Set myCell = Sheet5.Range("E15")
If Not Intersect(target, Range("X47:X51")) Is Nothing Then
Set rng = Range("X47:X51")
myCell.Value = ""
For Each Cell In rng
If Cell.Value <> "" Then
myCell.Value = myCell.Value & Cell.Value & vbNewLine
End If
Next
End If
If myCell.Value <> "" Then myCell.Value = Left(myCell.Value, Len(myCell.Value) - 1)
Set myCell = Sheet5.Range("E16")
If Not Intersect(target, Range("X58:X63")) Is Nothing Then
Set rng = Range("X58:X63")
myCell.Value = ""
For Each Cell In rng
If Cell.Value <> "" Then
myCell.Value = myCell.Value & Cell.Value & vbNewLine
End If
Next
End If
If myCell.Value <> "" Then myCell.Value = Left(myCell.Value, Len(myCell.Value) - 1)
Set myCell = Sheet5.Range("E17")
If Not Intersect(target, Range("X70:X77")) Is Nothing Then
Set rng = Range("X70:X77")
myCell.Value = ""
For Each Cell In rng
If Cell.Value <> "" Then
myCell.Value = myCell.Value & Cell.Value & vbNewLine
End If
Next
End If
If myCell.Value <> "" Then myCell.Value = Left(myCell.Value, Len(myCell.Value) - 1)
Set myCell = Sheet5.Range("E18")
If Not Intersect(target, Range("X84:X93")) Is Nothing Then
Set rng = Range("X84:X93")
myCell.Value = ""
For Each Cell In rng
If Cell.Value <> "" Then
myCell.Value = myCell.Value & Cell.Value & vbNewLine
End If
Next
End If
If myCell.Value <> "" Then myCell.Value = Left(myCell.Value, Len(myCell.Value) - 1)
Set myCell = Sheet5.Range("E19")
If Not Intersect(target, Range("X100:X106")) Is Nothing Then
Set rng = Range("X100:X106")
myCell.Value = ""
For Each Cell In rng
If Cell.Value <> "" Then
myCell.Value = myCell.Value & Cell.Value & vbNewLine
End If
Next
End If
If myCell.Value <> "" Then myCell.Value = Left(myCell.Value, Len(myCell.Value) - 1)
Set myCell = Sheet5.Range("E20")
If Not Intersect(target, Range("X113:X117")) Is Nothing Then
Set rng = Range("X113:X117")
myCell.Value = ""
For Each Cell In rng
If Cell.Value <> "" Then
myCell.Value = myCell.Value & Cell.Value & vbNewLine
End If
Next
End If
If myCell.Value <> "" Then myCell.Value = Left(myCell.Value, Len(myCell.Value) - 1)
Set myCell = Sheet5.Range("E22")
If Not Intersect(target, Range("I121")) Is Nothing Then
Set rng = Range("I121")
myCell.Value = ""
For Each Cell In rng
If Cell.Value <> "" Then
myCell.Value = Cell.Value
End If
Next
End If
If myCell.Value <> "" Then myCell.Value = Left(myCell.Value, Len(myCell.Value) - 1)
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
End Sub