Macro to delete duplicates ID contains same price for 1000 elements

Omar M

Board Regular
Joined
Jan 11, 2024
Messages
68
Office Version
  1. 2019
Platform
  1. Windows
Hi,
I don't want POWERQUERY or PIVOT TABLE , just CODE.
I would search for ID in column B contains same price in column E then should delete them except duplicates ID contains different prices.
I have about 1000 elements in column B after repeat elements many times the data could be 12000 rows. so I put the result in range (J:N) , I don't need NAME column.
a
ABCDEFGHIJKLMN
1DATEIDNAMEQTYUNIT PRICETOTAL
201/03/2024AVSD HJY00OMAR22.00222.004,884.00
302/03/2024AZSDCOMRAN10.00120.001,200.00
403/03/2024ASCV TYU T566AMERN10.00100.001,000.00
504/03/2024AVSD HJY00AMUR5.00222.001,110.00
605/03/2024AZSDCASIF5.00123.00615.00
706/03/2024ASCV TYU T566SAAF5.00110.00550.00
807/03/2024BBSDFRT-00SAAF1.00120.00120.00
908/03/2024BBSDFRT-01ASIF2.00124.00248.00
1009/03/2024BBSDFRT-00ASIF3.00120.00360.00
1110/03/2024VBGHYT 34YTY 66SUMMER2.00220.00440.00
1211/03/2024ASCV TYU T566SUMMER1.00110.00110.00
1312/03/2024VBGHYT 34YTY 66ASIF2.00225.00450.00
SS
Cell Formulas
RangeFormula
F2:F13F2=D2*E2



what I want
المصنف1
ABCDEFGHIJKLMN
1DATEIDNAMEQTYUNIT PRICETOTALDATEIDQTYUNIT PRICETOTAL
201/03/2024AVSD HJY00OMAR22.00222.004,884.0001/03/2024AVSD HJY0022.00222.004,884.00
302/03/2024AZSDCOMRAN10.00120.001,200.0002/03/2024AZSDC10.00120.001,200.00
403/03/2024ASCV TYU T566AMERN10.00100.001,000.0003/03/2024ASCV TYU T56610.00100.001,000.00
504/03/2024AVSD HJY00AMUR5.00222.001,110.0005/03/2024AZSDC5.00123.00615.00
605/03/2024AZSDCASIF5.00123.00615.0006/03/2024ASCV TYU T5665.00110.00550.00
706/03/2024ASCV TYU T566SAAF5.00110.00550.0007/03/2024BBSDFRT-001.00120.00120.00
807/03/2024BBSDFRT-00SAAF1.00120.00120.0008/03/2024BBSDFRT-012.00124.00248.00
908/03/2024BBSDFRT-01ASIF2.00124.00248.0010/03/2024VBGHYT 34YTY 662.00220.00440.00
1009/03/2024BBSDFRT-00ASIF3.00120.00360.0012/03/2024VBGHYT 34YTY 662.00225.00450.00
1110/03/2024VBGHYT 34YTY 66SUMMER2.00220.00440.00
1211/03/2024ASCV TYU T566SUMMER1.00110.00110.00
1312/03/2024VBGHYT 34YTY 66ASIF2.00225.00450.00
SS
Cell Formulas
RangeFormula
F2:F13,N2:N10N2=L2*M2


should delete data in range J:N when run macro every time .
Thanks
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this with a copy of your workbook.

VBA Code:
Sub Test()
  Dim lr As Long
  
  lr = Range("A" & Rows.Count).End(xlUp).Row
  Columns("J:N").ClearContents
  With Range("J1:N" & lr)
    .Value = Application.Index(Cells, Evaluate("row(1:" & lr & ")"), Array(1, 2, 4, 5, 6))
    .RemoveDuplicates Columns:=Array(2, 4), Header:=xlYes
  End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,226,503
Messages
6,191,421
Members
453,657
Latest member
DukeJester

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