Excel: How to remove duplicates but keep the first instance

In this blog post, I’m going to demonstrate how to remove duplicates in Excel but keep the first instance. Assume you have a list of values — say a spreadsheet of contact details and messages in your worksheet that contains some duplicates of those contacts from multiple messages they may have sent; you now need to delete the duplicates while keeping the initial row where the duplicated value is present so you can create a log of all your contacts with one record per contact. How would you go about doing this? Follow through for more information on how you can do this.

Step by step process – Excel: How to remove duplicates but keep the first instance

  1. First, open your excel document.
  2. (Optional step) Copy and paste the column or row you want to remove duplicates of into another sheet.
  3. Now use the column or row header to select the entire column or row (you can select multiple).
  4. Click on “Data.”
  5. After that click on remove duplicates.
  6. Ensure the box for your selected column is checked.
  7. Finally, press OK.
  • Get Excel for just $6.99 per month from the Microsoft Store!

Those are pretty much all the steps to remove duplicates. There won’t be any gaps where the original duplicate figures or records were; they will all completely disappear. Column based changes are only made to the selected rows or columns; no other column or row on your sheet will be affected. To achieve these results you will need to use the assistance of a filter and remove all but one set of records.

Because the goal is to give a list of unique values, filtering for unique values and deleting duplicate values are two identical jobs. However, there is a significant difference: when you filter for unique values, duplicate values are only temporarily hidden. Removing duplicate values, on the other hand, entails permanently erasing duplicate values.

All values in at least one row are identical to all values in another row, resulting in a duplicate value. Duplicate value comparison is based on what appears in the cell rather than the underlying value contained in the cell. The values are unique if you have the identical date value in two cells, one formatted as “3/8/2006” and the other as “Mar 8, 2006.”

surface pro 8Surface Go 3surface pro 8

Using a VBA script to remove duplicates but keep the first instance in Excel

By controlling graphical-user-interface (GUI) components like toolbars and menus, conversation boxes, and forms, VBA allows users to modify beyond what is generally possible with MS Office host programs (VBA is not a stand-alone software). VBA may be used to build user-defined functions (UDFs), access Windows APIs, and automate particular computer operations and computations. To delete duplicates but preserve the first instance in a column, execute the VBA code below.

Step by step: Using a VBA script to remove duplicates but keep the first instance

  • To enter the Microsoft Visual Basic for Applications dialogue box, press Alt + F11.
  • Select Insert > Module from the Microsoft Visual Basic for Applications dialogue box. Then, in the code box, copy and paste the code below.
  • Remove duplicates in VBA code but preserve the first instance.
Sub TrimExcessSpaces()    
Dim Rng As Range    
Dim WorkRng As Range    
Dim dic As Variant    
Set dic = CreateObject(“Scripting.Dictionary”)    
On Error Resume Next    
xTitleId = “KutoolsforExcel”    
Set WorkRng = Application.Selection    
Set WorkRng = Application.InputBox(“Range”, xTitleId, WorkRng.Address, Type: = 8)    
Set WorkRng = WorkRng.Columns(1)    
For Each Rng In WorkRng.Cells        
dic(Rng.Value) = “”    
Next    
WorkRng.ClearContents    
WorkRng.Range(“A1”).Resize(UBound(dic.Keys) + 1, 1) =        Application.WorksheetFunction.Transpose(dic.Keys)
End Sub

The script will run on your Sheet and remove duplicates across the selected rows or columns. Make sure you have the correct JS format shown above. Scripting requires a case sensitive protocol that must be adhered to each time you want to make changes that will reflex a significant role on your Sheet such as data removal like in this example.

VBA is an event-driven tool, which means you may use it to instruct the computer to do a certain action or sequence of events. You accomplish this by putting commands into an editing module to create bespoke macros (short for macroinstructions).

A macro is a set of characters whose input results in another set of characters (its output) that performs certain computational tasks. Because VBA is the version of Visual Basic that comes with Microsoft Office 2010, you don’t need to buy the VBA program.

Finance is fundamentally about manipulating large volumes of data, which is why VBA is so prevalent in the financial services industry. If you work in finance, VBA is almost certainly running in programs you use on a daily basis, whether you realize it or not. Some employment in the industry demand VBA expertise, while others do not.

In either case, knowing the newest technology developments in your field and how to leverage automation in your day-to-day work is critical if you want to pursue a career in finance. VBA is simple to learn for individuals who have little or no experience with computer programming.

security office365 windows 11
info Recommended Software

In-depth – Step by step process – Excel: How to remove duplicates but keep the first instance

  • Firstly, open your excel document.
  • (Optional step) Copy and paste the column or row you want to remove duplicates of into another sheet.
  • Now use the column or row header to select the entire column or row (you can select multiple).
  • Click on “Data”.
  • After that click on remove duplicates.
  • Ensure the box for your selected column is checked,
  • Finally, press OK.

That’s it for this Blog thank you for taking time out to read our content, please feel free to email our team about how it went if you followed the steps or if you need more help with the questions we answered in this Blog.

Saajid Gangat

Saajid Gangat has been a researcher and content writer at Business Tech Planet since 2021. Saajid is a tech-savvy writer with expertise in web and graphic design and has extensive knowledge of Microsoft 365, Adobe, Shopify, WordPress, Wix, Squarespace, and more! You can connect with Saajid on Linkedin.

Recent Posts