Let's give it another try:
Dim oldSH As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 24 And Target.CountLarge = 1 Then
oldSH = Target.Value
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B:AA")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim SNo As Range, newrow As ListRow, tbl As ListObject
If oldSH = "" And Target.Column = 24 Then
Dim lastRow As Long
If Not Evaluate("isref('" & Target.Value & "'!A1)") Then
Sheets.Add(After:=Sheets(Sheets.Count)).Name = Target.Value
With Sheets(Target.Value)
Rows(3).Copy .Cells(1, 1)
.ListObjects.Add(xlSrcRange, .Range("$A$1:$AA$1"), , xlYes).Name = Target.Value
.Range("A1").AutoFilter
Set tbl = .ListObjects(Target.Value)
Set newrow = tbl.ListRows.Add
lastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
Target.EntireRow.Copy .Cells(lastRow, 1)
End With
Else
With Sheets(Target.Value)
Set tbl = .ListObjects(Target.Value)
Set newrow = tbl.ListRows.Add
lastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
Target.EntireRow.Copy .Cells(lastRow, 1)
End With
End If
Sheets("APPLICATIONS").Activate
ElseIf oldSH <> "" And Target.Column = 24 Then
If Not Evaluate("isref('" & Target.Value & "'!A1)") Then
Sheets.Add(After:=Sheets(Sheets.Count)).Name = Target.Value
With Sheets(Target.Value)
Rows(3).Copy .Cells(1, 1)
.ListObjects.Add(xlSrcRange, .Range("$A$1:$AA$1"), , xlYes).Name = Target.Value
.Range("A1").AutoFilter
Set tbl = .ListObjects(Target.Value)
Set newrow = tbl.ListRows.Add
lastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
Set SNo = Sheets(oldSH).Range("A:A").Find(Range("A" & Target.Row).Value, LookIn:=xlValues, lookat:=xlWhole)
If Not SNo Is Nothing Then
With Sheets(oldSH)
SNo.EntireRow.Copy Sheets(Target.Value).Cells(lastRow, 1)
Sheets(Target.Value).Cells(lastRow, 24) = Target
SNo.EntireRow.Delete
End With
End If
End With
Else
Set SNo = Sheets(oldSH).Range("A:A").Find(Range("A" & Target.Row).Value, LookIn:=xlValues, lookat:=xlWhole)
If Not SNo Is Nothing Then
With Sheets(Target.Value)
Set tbl = .ListObjects(Target.Value)
Set newrow = tbl.ListRows.Add
lastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
SNo.EntireRow.Copy .Cells(lastRow, 1)
.Cells(lastRow, 24) = Target
SNo.EntireRow.Delete
End With
End If
End If
End If
If Target.Column <> 24 And Range("X" & Target.Row) <> "" Then
With Sheets(Range("X" & Target.Row).Value)
Set SNo = .Range("A:A").Find(Range("A" & Target.Row).Value, LookIn:=xlValues, lookat:=xlWhole)
If Not SNo Is Nothing Then
.Cells(SNo.Row, Target.Column) = Target.Value
End If
End With
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Bookmarks