VBA count duplicates based on column then delete duplicate, but keep one

RomanNaz

New Member
Joined
May 31, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Hello! Trying to make sheet for import UPS shipments from SOR.
I have excel with orders and shipment data. 1 row = 1 shipping box
I need to find duplicates in column with order number, add count of duplicates to cell (e.g. "number of boxes"), then delete duplicate rows but keep one
Before:
Order Name Phone
1234 John 8909809
1234 John 8909809
1234 John 8909809
1248 Mike 9898799
1248 Mike 9898799
1248 Mike 9898799
1234 John 8909809

After:
Order Name Phone NumbrBoxes
1234 John 8909809 4
1248 Mike 9898799 3

I really appreciate any help you can provide
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,524
Office Version
  1. 2010
Platform
  1. Windows
Hi, according to Excel basics a VBA demonstration as a beginner starter :​
VBA Code:
Sub Demo1()
    Dim R&
        R = [A1].CurrentRegion.Rows.Count:  If R < 3 Then Beep: Exit Sub
        Application.ScreenUpdating = False
        [D1] = "Boxes #"
    With Range("A2:D" & R).Columns
        .Item(4).Formula = "=COUNTIF($A$2:$A$" & R & ",A2)"
        .Item(4).Formula = .Item(4).Value2
        .RemoveDuplicates 1, 2
    End With
        Application.ScreenUpdating = True
End Sub
 

Forum statistics

Threads
1,143,623
Messages
5,719,804
Members
422,245
Latest member
Kebad

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
Top