Super newbie looking for help improving VBA code Efficiency

eMHDfNhuwLhQCzJ

New Member
Joined
May 4, 2021
Messages
6
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Btw both named ranges Tailcode and Log_Tailcode will only ever contain a maximum of 19 records.
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,652
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top