Posts

Showing posts from June, 2023

Compare Two Worksheets with VBA

Image
[ From  Compare Two Worksheets with VBA — Excel Dashboards VBA (thesmallman.com) ] Compare Two Worksheets with VBA Compare two worksheets with VBA and output the differences to a new worksheet.  With the following vba macro, you can compare the contents of two worksheets and only display the differences. The following will compare Column A in the active sheet (Sheet1) for example with Column A in Sheet2.  It uses the scripting dictionary so the process is very fast for high volumes of data.  Of course this procedure could be replicated with a Vlookup in native Excel without the output to a new area. Option Explicit Sub  NoMatches()  'Excel vba to remove duplicates. Dim dic As Object Dim ar As Variant Dim ar1 As Variant Dim var As Variant Dim i As Long Dim n As Long Set dic=Createobject("Scripting.Dictionary") dic.CompareMode=1 ar=Range("A2", Range("A" & Rows.Count).End(xlUp)).Value var=Sheet2.Range("A2", Sheet2.Range("A" & R

Excel VBA Dictionary – A Complete Guide

Image
[ From  Excel VBA Dictionary - A Complete Guide - Excel Macro Mastery ] Excel VBA Dictionary – A Complete Guide by  Paul Kelly  |  |  Data Structures VBA ,  Most Popular  |  226 comments “The greatest masterpiece in literature is only a dictionary out of order.” – Jean Cocteau   Contents  [ hide ] 1  A Quick Guide to the VBA Dictionary 2  What is the VBA Dictionary? 3  Download the Source Code 4  Dictionary Webinar 5  A Dictionary in real world terms 6  A Simple Example of using the VBA Dictionary 7  Creating a Dictionary 7.1  Early versus Late Binding 8  Adding Items to the Dictionary 9  Assigning a Value 10  Checking if a Key Exists 11  Storing Multiple Values in One Key 12  Other useful functions 13  The Key and Case Sensitivity 13.1  Things to Watch Out For 14  Reading through the Dictionary 15  Sorting the Dictionary 15.1  Sorting by keys 15.2  Sorting by values 16  Troubleshooting the Dictionary 16.1  Missing Reference 16.2  Exists is not Working 16.3  Object Variable Error 16.4