Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
2,645 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim rng As Range
Dim temp As Variant
' Set your worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
' Check if the change is made in column L and the cell is not empty
If Target.Column = 12 And Not IsEmpty(Target) Then
' Find matching value in column L
Set rng = ws.Columns("L").Find(Target.Value, LookIn:=xlValues, lookat:=xlWhole)
' If a match is found and it's not the same cell where the change was made
If Not rng Is Nothing And rng.Address <> Target.Address Then
' Ignore the change and exit the subroutine
Exit Sub
Else
' Find matching value in column E
Set rng = ws.Columns("E").Find(Target.Value)
' If a match is found
If Not rng Is Nothing Then
' Store the row from column A to H of the matching row in a temporary variable
temp = ws.Range("A" & rng.Row & ":H" & rng.Row).Value
' Copy the row from column A to H to the matching row in column L
ws.Range("A" & rng.Row & ":H" & rng.Row).Value = ws.Range("A" & Target.Row & ":H" & Target.Row).Value
' Move the stored row to the original location of the typed row
ws.Range("A" & Target.Row & ":H" & Target.Row).Value = temp
End If
End If
.Row & ":H" & Target.Row).Value = temp
EndPrivate Sub Worksheet_Change(ByVal Target As Range)