Option Explicit
Dim CurrentPlotLabel As String
Dim CurrentPlotRow As Long
Dim CurrentPlotColumn As Long
Dim CurrentColorIndex As Long
Dim NewPlotLabel As String
Dim NewPlotRow As Long
Dim NewPlotColumn As Long
'Store the current Label, Row, Column and .Interior.ColorIndex of the currently selected cell
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count = 1 Then
If Not Intersect(Target, Range("Labels")) Is Nothing Then
CurrentPlotLabel = Target.Offset(0, 0).Value
CurrentColorIndex = Target.Offset(0, 0).Interior.ColorIndex
CurrentPlotRow = Target.Offset(0, 1).Value
CurrentPlotColumn = Target.Offset(0, 2).Value
End If
If Not Intersect(Target, Range("Rows")) Is Nothing Then
CurrentPlotLabel = Target.Offset(0, -1).Value
CurrentColorIndex = Target.Offset(0, -1).Interior.ColorIndex
CurrentPlotRow = Target.Offset(0, 0).Value
CurrentPlotColumn = Target.Offset(0, 1).Value
End If
If Not Intersect(Target, Range("Columns")) Is Nothing Then
CurrentPlotLabel = Target.Offset(0, -2).Value
CurrentColorIndex = Target.Offset(0, -2).Interior.ColorIndex
CurrentPlotRow = Target.Offset(0, -1).Value
CurrentPlotColumn = Target.Offset(0, 0).Value
End If
End If
End Sub
'Clear the value and .Interior.ColorIndex in Cells(CurrentPlotRow, CurrentPlotColumn)
'Replace it with the amended Label and .Interior.ColorIndex in Cells(NewPlotRow, NewPlotColumn) as required
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 Then
If Not Intersect(Target, Range("Labels")) Is Nothing Then
Cells(CurrentPlotRow, CurrentPlotColumn).ClearContents
Cells(CurrentPlotRow, CurrentPlotColumn).Interior.ColorIndex = xlNone
NewPlotRow = Target.Offset(0, 1).Value
NewPlotColumn = Target.Offset(0, 2).Value
Cells(NewPlotRow, NewPlotColumn).Formula = Target.Offset(0, 0).Formula
Cells(NewPlotRow, NewPlotColumn).Interior.ColorIndex = CurrentColorIndex
End If
If Not Intersect(Target, Range("Rows")) Is Nothing Then
Cells(CurrentPlotRow, CurrentPlotColumn).ClearContents
Cells(CurrentPlotRow, CurrentPlotColumn).Interior.ColorIndex = xlNone
NewPlotRow = Target.Offset(0, 0).Value
NewPlotColumn = Target.Offset(0, 1).Value
Cells(NewPlotRow, NewPlotColumn).Formula = Target.Offset(0, -1).Formula
Cells(NewPlotRow, NewPlotColumn).Interior.ColorIndex = CurrentColorIndex
End If
If Not Intersect(Target, Range("Columns")) Is Nothing Then
Cells(CurrentPlotRow, CurrentPlotColumn).ClearContents
Cells(CurrentPlotRow, CurrentPlotColumn).Interior.ColorIndex = xlNone
NewPlotRow = Target.Offset(0, -1).Value
NewPlotColumn = Target.Offset(0, 0).Value
Cells(NewPlotRow, NewPlotColumn).Formula = Target.Offset(0, -2).Formula
Cells(NewPlotRow, NewPlotColumn).Interior.ColorIndex = CurrentColorIndex
End If
End If
End Sub