eMHDfNhuwLhQCzJ
New Member
- Joined
- May 4, 2021
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
Hello. I've optimized this code to the best of my abilities. If anyone can provide more elegant code optimizations for speed it would be very much appreciated.
VBA Code:
'These lines place the Tailcode named range values and the Log sheet Tailcode Named Range values for comparison.
Range("P33").Formula2R1C1 = "=SORT(VSTACK(Tailcode,Log_Tailcode),1,1,TRUE)"
Range("P33").Activate
'Since the formula used is creates an array this produces cells with values only and removes the array.
Range(Selection, Selection.End(xlDown)).Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'This removes both pairs of duplicates detected so that only new Tailcodes from the lists sheet remain. Credit Rick Rothstein https://www.mrexcel.com/board/threads/vba-delete-both-duplicates-entire-row.854171/
Addr = "P33:P" & Cells(Rows.Count, "P").End(xlUp).Row
Range(Addr) = Evaluate("IF(COUNTIF(P:P," & Addr & ")>1,""#N/A""," & Addr & ")")
On Error Resume Next
Columns("P").SpecialCells(xlConstants, xlErrors).Delete Shift:=xlUp
On Error GoTo 0
'This section copies the newly filtered Tailcodes to the first empty cell in the Tailcode column of Log.
Range("P33").Activate
Range(Selection, Selection.End(xlDown)).Copy
Range("B1048576").Activate
Selection.End(xlUp).Offset(1, 0).Range("A1").Activate
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Columns("N:P").Clear