Merging duplicates items after words contains colon based on different price for the same ID

abdo meghari

Well-known Member
Joined
Aug 3, 2021
Messages
612
Office Version
  1. 2019
Hello,
I would merge quantity in column E for duplicates BRANDS in column D based on column C for each range contains colon for each name MOVEMENT word is existed after colon .
, but when merge QTY should be based on the same price in unit price in column F . so you will note some the same duplicates IDs contain different price , so don't merge QTY for the same duplicates IDs contain different price .
when merge data should brings column C:F from INVOICES sheet and insert TOTAL column and calculate as the formula is existed .
every time when run the macro should replace new data with old data, also should sort data for each range based on column C from small to big based on numbers . .
last thing I have many ranges contains words and suffix :
I realized error about my topic . should merge same ID based on same price, not different price.
I can't correct my topic, sorry about this mistake!!

split brands.xlsm
ABCDEFG
2MOVEMENT : PURCHASING
3DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
42024.01.021141284GC 1200R20 AZ0026 CHI80895.000242,560.000
51285GC 1200R20 AZ0183 CHI40925.000
61385GC 315/80R22.5 AT161 CHI20735.000
71287GC 315/80R22.5 AZ126 CHI20735.000
81294GC 315/80R22.5 AZ188 CHI20745.000
91241BS 1200R20 G580 JAP402,035.000
101227BS 215/70R15C R623 THI8425.000
111221BS 205/70R15C R623 THI12405.000
12DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
132024.01.091211287GC 315/80R22.5 AZ126 CHI14735.00010,290.000
14DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
152024.01.101251227BS 215/70R15C R623 THI2425.000850.000
16DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
172024.01.201481287GC 315/80R22.5 AZ126 CHI26735.00019,110.000
18DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
192024.01.201491221BS 205/70R15C R623 THI50405.000391,650.000
201227BS 215/70R15C R623 THI12425.000
211241BS 1200R20 G580 JAP1802,035.000
22DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
232024.03.302171285GC 1200R20 AZ0183 CHI101,225.00012,250.000
24DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
252024.04.092261227BS 215/70R15C R623 THI4544.0002,176.000
26DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
272024.04.142301285GC 1200R20 AZ0183 CHI401,205.00081,950.000
281284GC 1200R20 AZ0026 CHI301,125.000
29DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
302024.04.172361284GC 1200R20 AZ0026 CHI201,125.00046,600.000
311285GC 1200R20 AZ0183 CHI201,205.000
32MOVEMENT : SELLING
33DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
342024.01.245611306BS 750R16 R230 JAP10775.0007,750.000
35DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
362024.01.245621306BS 750R16 R230 JAP2780.0001,560.000
37DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
382024.01.245631306BS 750R16 R230 JAP2780.0003,100.000
391305BS 700R16 R230 JAP2770.000
40
41SUMMARY
42TOTAL PURCHASE807,436.000
43TOTAL SELLING12,410.000
INVOICES




result


split brands.xlsm
ABCDEF
2MOVEMENT : PURCHASING
3ITEMCODEBRANDQTYUNIT PRICETOTAL
411221BS 205/70R15C R623 THI62405.00025,110.000
521227BS 215/70R15C R623 THI22425.0009,350.000
631227BS 215/70R15C R623 THI4544.0002,176.000
741241BS 1200R20 G580 JAP2202,035.000447,700.000
851284GC 1200R20 AZ0026 CHI80895.00071,600.000
961284GC 1200R20 AZ0026 CHI501,125.00056,250.000
1071285GC 1200R20 AZ0183 CHI40925.00037,000.000
1181285GC 1200R20 AZ0183 CHI101,225.00012,250.000
1291285GC 1200R20 AZ0183 CHI601,205.00072,300.000
13101385GC 315/80R22.5 AT161 CHI20735.00014,700.000
14111294GC 315/80R22.5 AZ188 CHI20745.00014,900.000
15121287GC 315/80R22.5 AZ126 CHI60735.00044,100.000
16MOVEMENT : SELLING
17ITEMCODEBRANDQTYUNIT PRICETOTAL
1811305BS 700R16 R230 JAP2770.0001,540.000
1921306BS 750R16 R230 JAP10775.0007,750.000
2031306BS 750R16 R230 JAP4780.0003,120.000
21
22SUMMARY
23TOTAL PURCHASE807,436.000
24TOTAL SELLING12,410.000
RESULT
Cell Formulas
RangeFormula
F18:F20,F4:F15F4=D4*E4


I hope to don't make any mistake .
 
Last edited:
when I run the code this is what I got.
ERROR MERGING.xlsm
ABCDEF
1
2MOVEMENT : PURCHASING
3ITEMCODEBRANDQTYUNIT PRICETOTAL
411300XPRO 70A L KOR4540.0002,160.000
521300XPRO 70A L KOR10515.0005,150.000
631334XPRO 70A R KOR4540.0002,160.000
741334XPRO 70A R KOR15510.0007,650.000
851335XPRO 150A L KOR61,000.0006,000.000
961337XPRO 55A L KOR10390.0003,900.000
1071338XPRO 60A L KOR19425.0008,075.000
1181339XPRO 90A L KOR18605.00010,890.000
1291341XPRO 100A L KOR10620.0006,200.000
13101343KM 215/65R16 TA21 KOR5435.0002,175.000
14111448DUNLOP 285/60R18 AT25 JAP11,110.0001,110.000
15121471BS 1400R20 R180 JAP24,500.0009,000.000
16131495XPRO 200A L KOR41,285.0005,140.000
17141496XPRO 100A L KOR واطية1625.000625.000
18151518KM 195/65R15 TA21 KOR4350.0001,400.000
19161540VEGA 55A L KOR1400.000400.000
20171567DUNLOP 285/65R17 JAP4950.0003,800.000
21181568MOTORMECH 150A L KOR21,000.0002,000.000
22191586NOVA 200A L KOR21,500.0003,000.000
23201588BATTREY 30A CHI1275.000275.000
24211590BOHANO 55A L JAP1370.000370.000
25221594APPLLO 265/65R17 INDIA4595.0002,380.000
26231595XPRO 100A R KOR10610.0006,100.000
27241596YOKOHAMA 7A MALAYSIA 1265.000265.000
28251598XPRO 80A L KPOR3570.0001,710.000
29261619VEGA 70A R KOR10500.0005,000.000
30271620YOKOHAMA 205/65R16 ES32 JAP8455.0003,640.000
31281621LASSA 4*4 235/70R16 A/T2 TR8575.0004,600.000
32291623LASSA 235/50R19 H/P2 TR8560.0004,480.000
33301624DUNLOP 265/70R18 AT23 JAP81,100.0008,800.000
34311626KM 285/75R16 MT51 VIT16835.00013,360.000
35321631KM 245/70R17 AT52 VIT8645.0005,160.000
36
37SUMMARY
38TOTAL PURCHASE170,305.000
39CURRENT BALANCE-438,240.000
RESULT
Cell Formulas
RangeFormula
F4:F35F4=D4*E4



and what I want
ERROR MERGING.xlsm
ABCDEF
1
2MOVEMENT : PURCHASING
3ITEMCODEBRANDQTYUNIT PRICETOTAL
411300XPRO 70A L KOR4540.0002,160.000
521300XPRO 70A L KOR10515.0005,150.000
631334XPRO 70A R KOR4540.0002,160.000
741334XPRO 70A R KOR15510.0007,650.000
851335XPRO 150A L KOR241,000.00024,000.000
961337XPRO 55A L KOR10390.0003,900.000
1071338XPRO 60A L KOR1522425.000646,850.000
1181339XPRO 90A L KOR99605.00059,895.000
1291341XPRO 100A L KOR10620.0006,200.000
13101343KM 215/65R16 TA21 KOR5435.0002,175.000
14111448DUNLOP 285/60R18 AT25 JAP11,110.0001,110.000
15121471BS 1400R20 R180 JAP24,500.0009,000.000
16131495XPRO 200A L KOR41,285.0005,140.000
17141496XPRO 100A L KOR واطية1625.000625.000
18151518KM 195/65R15 TA21 KOR4350.0001,400.000
19161540VEGA 55A L KOR1400.000400.000
20171567DUNLOP 285/65R17 JAP22950.00020,900.000
21181568MOTORMECH 150A L KOR21,000.0002,000.000
22191586NOVA 200A L KOR21,500.0003,000.000
23201588BATTREY 30A CHI1275.000275.000
24211590BOHANO 55A L JAP1370.000370.000
25221594APPLLO 265/65R17 INDIA4595.0002,380.000
26231595XPRO 100A R KOR10610.0006,100.000
27241596YOKOHAMA 7A MALAYSIA 1265.000265.000
28251598XPRO 80A L KPOR111570.00063,270.000
29261619VEGA 70A R KOR55500.00027,500.000
30271620YOKOHAMA 205/65R16 ES32 JAP44455.00020,020.000
31281621LASSA 4*4 235/70R16 A/T2 TR44575.00025,300.000
32291623LASSA 235/50R19 H/P2 TR44560.00024,640.000
33301624DUNLOP 265/70R18 AT23 JAP441,100.00048,400.000
34311626KM 285/75R16 MT51 VIT88835.00073,480.000
35321631KM 245/70R17 AT52 VIT44645.00028,380.000
36
37SUMMARY
38TOTAL PURCHASE170,305.000
39CURRENT BALANCE-438,240.000
RESULT
Cell Formulas
RangeFormula
F4:F35F4=D4*E4
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Thanks for the samples. Try this version

VBA Code:
Sub Get_Results_v5()
  Dim d As Object
  Dim a As Variant
  Dim wsI As Worksheet, wsR As Worksheet
  Dim fr As Long, lr As Long, vlr As Long, i As Long, nr As Long
  Dim s As String
  
  Application.ScreenUpdating = False
  Set wsI = Sheets("INVOICES")
  Set wsR = Sheets("RESULT")
  wsR.UsedRange.EntireColumn.Delete
  Set d = CreateObject("Scripting.Dictionary")
  nr = 2
  With wsI.Columns("D")
    fr = .Find(What:="MOVEMENT", LookAt:=xlPart).Row
    vlr = .Cells(.Rows.Count).End(xlUp).Row
    Do
      lr = .Find(What:="MOVEMENT", After:=.Cells(fr), LookAt:=xlPart).Row - 1
      If lr < fr Then lr = vlr
      a = wsI.Range("C" & fr & ":F" & lr).Value
      For i = 2 To UBound(a)
        If a(i, 1) <> "CODE" Then
          s = a(i, 1) & ";" & a(i, 2) & ";;" & a(i, 4)
          d(s) = d(s) + Val(a(i, 3))
        End If
      Next i
      wsI.Range("B" & fr).Resize(2, 6).Copy Destination:=wsR.Range("A" & nr)
      wsR.Range("A" & nr + 1).Value = "ITEM"
      With wsR.Range("B" & nr + 2).Resize(d.Count)
        .Value = Application.Transpose(d.Keys)
        .TextToColumns DataType:=xlDelimited, Semicolon:=True, Comma:=False, Space:=False, Other:=False
        .Offset(, 2).Value = Application.Transpose(d.Items)
        .Offset(, 4).FormulaR1C1 = "=RC[-2]*RC[-1]"
        .Resize(, 5).Sort Key1:=.Columns(1), Order1:=xlAscending, Header:=xlNo
        .Offset(, -1).Value = Evaluate("row(1:" & d.Count & ")")
        With .Cells(0, 0).Resize(d.Count + 1, 6)
          .BorderAround xlContinuous
          .Borders(xlInsideVertical).LineStyle = xlContinuous
          .Borders(xlInsideHorizontal).LineStyle = xlContinuous
        End With
        .Cells(-1, 2).BorderAround xlContinuous
      End With
      nr = nr + d.Count + 2
      fr = .Find(What:="MOVEMENT", After:=.Cells(fr), LookAt:=xlPart).Row
      d.RemoveAll
    Loop Until fr < lr
  End With
  wsI.Range("A" & Rows.Count).End(xlUp).CurrentRegion.Copy Destination:=wsR.Range("A" & nr + 1)
  With wsR.Range("A" & Rows.Count).End(xlUp).CurrentRegion
    .BorderAround xlContinuous
    .Borders(xlInsideVertical).LineStyle = xlContinuous
    .Borders(xlInsideHorizontal).LineStyle = xlContinuous
  End With
  wsR.Range("B" & nr + 3).Resize(2).NumberFormat = "#,##0.000"
  wsR.Columns("E:F").NumberFormat = "#,##0.000"
  With wsR.UsedRange
    .ColumnWidth = 255
    .Columns.AutoFit
    .Rows.AutoFit
  End With
  wsR.DrawingObjects.Delete
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
:confused: I thought that you did not want the button copied from the INVOICES sheet to the RESULT sheet
sorry about that !
but what I meant when running the macro I noticed the code will copy the button again next to first button
so will be come two buttons, not one button that should be.
 
Upvote 0
Well, I am unsure about your buttons and what they do, or should do. In your sample file ...
  • There is a button on RESULT that appears to run the "Get_Results_v3 code
  • There is a button on INVOICES that does nothing for me.
    Why is it there?
    Is is needed?
    What does it do or what should it do?
 
Upvote 0
Try this
  1. In INVOICES, right-click the button and choose 'Size & Properties'
  2. Under Properties select "Don't move or size with cells"
  3. In the _v5 code remove the following line near the end of the code wsR.DrawingObjects.Delete
 
Upvote 0
Try this
  1. In INVOICES, right-click the button and choose 'Size & Properties'
  2. Under Properties select "Don't move or size with cells"
  3. In the _v5 code remove the following line near the end of the code wsR.DrawingObjects.Delete
that's works .(y)
I appreciate for your back for me and solve all of my problems.
many thanks for your time , help.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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