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
652
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:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi peter again
I try implement for this data , but suddenly merge error as highlighted , what's the reason?!
KashfMabiatReport1 with code.xls
ABCDEFG
3DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
42024.07.2011351568MOTORMECH 150A L KOR21,000.0009,995.000
51586NOVA 200A L KOR21,500.000
61540VEGA 55A L KOR1400.000
71300XPRO 70A L KOR4540.000
81334XPRO 70A R KOR4540.000
91588BATTREY 30A CHI1275.000
10DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
112024.07.2211411590BOHANO 55A L JAP1370.000370.000
12DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
132024.07.2311461343KM 215/65R16 TA21 KOR5435.0003,575.000
141518KM 195/65R15 TA21 KOR4350.000
15DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
162024.07.279700000021335XPRO 150A L KOR21,000.0006,115.000
171496XPRO 100A L KOR واطية1625.000
181448DUNLOP 285/60R18 AT25 JAP11,110.000
191594APPLLO 265/65R17 INDIA4595.000
20DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
212024.07.289700000111471BS 1400R20 R180 JAP24,500.0009,000.000
22DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
232024.07.299700000171495XPRO 200A L KOR41,285.00044,780.000
241335XPRO 150A L KOR41,000.000
251595XPRO 100A R KOR10610.000
261341XPRO 100A L KOR10620.000
271334XPRO 70A R KOR15510.000
281300XPRO 70A L KOR10515.000
291338XPRO 60A L KOR15425.000
301337XPRO 55A L KOR10390.000
311596YOKOHAMA 7A MALAYSIA 1265.000
32DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
332024.08.019700000261598XPRO 80A L KPOR1570.000570.000
34DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
352024.08.279700002161620YOKOHAMA 205/65R16 ES32 JAP4455.00015,160.000
361624DUNLOP 265/70R18 AT23 JAP41,100.000
371621LASSA 4*4 235/70R16 A/T2 TR4575.000
381623LASSA 235/50R19 H/P2 TR4560.000
391567DUNLOP 285/65R17 JAP2950.000
401619VEGA 70A R KOR5500.000
41DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
422024.08.299700000221339XPRO 90A L KOR9605.0005,445.000
43DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
442024.08.319700002271598XPRO 80A L KPOR1570.000570.000
45DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
462024.08.319700002331626KM 285/75R16 MT51 VIT8835.0006,680.000
47DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
482024.09.029700002471338XPRO 60A L KOR2425.000850.000
49DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
502024.09.049700002721631KM 245/70R17 AT52 VIT4645.0002,580.000
51DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
522024.08.279700002161620YOKOHAMA 205/65R16 ES32 JAP4455.00015,160.000
531624DUNLOP 265/70R18 AT23 JAP41,100.000
541621LASSA 4*4 235/70R16 A/T2 TR4575.000
551623LASSA 235/50R19 H/P2 TR4560.000
561567DUNLOP 285/65R17 JAP2950.000
571619VEGA 70A R KOR5500.000
58DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
592024.08.299700000221339XPRO 90A L KOR9605.0005,445.000
60DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
612024.08.319700002271598XPRO 80A L KPOR1570.000570.000
62DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
632024.08.319700002331626KM 285/75R16 MT51 VIT8835.0006,680.000
64DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
652024.09.029700002471338XPRO 60A L KOR2425.000850.000
66DATEINVOICE NOCODEBRANDQTYUNIT PRICETOTAL
672024.09.049700002721631KM 245/70R17 AT52 VIT4645.0002,580.000
INVOICES



this is what I got
KashfMabiatReport1 with code.xls
ABCDEF
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 KOR1625.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
RESULT
Cell Formulas
RangeFormula
F4:F35F4=D4*E4


seem adding numbers without sum for some brands !
 
Upvote 0
PQ editor will inform me the Mcode was written in a newer version.
I have never seen this before. You are on 2019 and I am on 365. My code should be compatible with your version. Is your source the same as in my Mcode.
 
Upvote 0
Hi peter again
I try implement for this data , but suddenly merge error as highlighted , what's the reason?!
Sorry, I have been away for a few weeks. If you still need help with this then you would need to provide a fuller set of sample data that produces the result that you have shown.

The sample data in post 22
  • does not have any "MOVEMENT .." cells though I did assume cell D2 was "MOVEMENT : PURCHASING"
  • does not have a SUMMARY section at the bottom left like the previous data.
With the limited sample that you have provided, I was not able to produce the results shown in the second mini-sheet in post 22.
 
Upvote 0
Sorry, I have been away for a few weeks
I noticed it .;)
here is again
ERROR MERGING.xlsm
ABCDEFG
2MOVEMENT : PURCHASING
3DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
42024.07.2011351568MOTORMECH 150A L KOR21,000.0009,995.000
51586NOVA 200A L KOR21,500.000
61540VEGA 55A L KOR1400.000
71300XPRO 70A L KOR4540.000
81334XPRO 70A R KOR4540.000
91588BATTREY 30A CHI1275.000
10DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
112024.07.2211411590BOHANO 55A L JAP1370.000370.000
12DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
132024.07.2311461343KM 215/65R16 TA21 KOR5435.0003,575.000
141518KM 195/65R15 TA21 KOR4350.000
15DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
162024.07.279700000021335XPRO 150A L KOR21,000.0006,115.000
171496XPRO 100A L KOR واطية1625.000
181448DUNLOP 285/60R18 AT25 JAP11,110.000
191594APPLLO 265/65R17 INDIA4595.000
20DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
212024.07.289700000111471BS 1400R20 R180 JAP24,500.0009,000.000
22DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
232024.07.299700000171495XPRO 200A L KOR41,285.00044,780.000
241335XPRO 150A L KOR41,000.000
251595XPRO 100A R KOR10610.000
261341XPRO 100A L KOR10620.000
271334XPRO 70A R KOR15510.000
281300XPRO 70A L KOR10515.000
291338XPRO 60A L KOR15425.000
301337XPRO 55A L KOR10390.000
311596YOKOHAMA 7A MALAYSIA 1265.000
32DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
332024.08.019700000261598XPRO 80A L KPOR1570.000570.000
34DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
352024.08.279700002161620YOKOHAMA 205/65R16 ES32 JAP4455.00015,160.000
361624DUNLOP 265/70R18 AT23 JAP41,100.000
371621LASSA 4*4 235/70R16 A/T2 TR4575.000
381623LASSA 235/50R19 H/P2 TR4560.000
391567DUNLOP 285/65R17 JAP2950.000
401619VEGA 70A R KOR5500.000
41DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
422024.08.299700000221339XPRO 90A L KOR9605.0005,445.000
43DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
442024.08.319700002271598XPRO 80A L KPOR1570.000570.000
45DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
462024.08.319700002331626KM 285/75R16 MT51 VIT8835.0006,680.000
47DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
482024.09.029700002471338XPRO 60A L KOR2425.000850.000
49DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
502024.09.049700002721631KM 245/70R17 AT52 VIT4645.0002,580.000
51DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
522024.08.279700002161620YOKOHAMA 205/65R16 ES32 JAP4455.00015,160.000
531624DUNLOP 265/70R18 AT23 JAP41,100.000
541621LASSA 4*4 235/70R16 A/T2 TR4575.000
551623LASSA 235/50R19 H/P2 TR4560.000
561567DUNLOP 285/65R17 JAP2950.000
571619VEGA 70A R KOR5500.000
58DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
592024.08.299700000221339XPRO 90A L KOR9605.0005,445.000
60DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
612024.08.319700002271598XPRO 80A L KPOR1570.000570.000
62DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
632024.08.319700002331626KM 285/75R16 MT51 VIT8835.0006,680.000
64DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
652024.09.029700002471338XPRO 60A L KOR2425.000850.000
66DATE INVOICE NOCODEBRANDQTYUNIT PRICETOTAL
672024.09.049700002721631KM 245/70R17 AT52 VIT4645.0002,580.000
68
69SUMMARY
70TOTAL PURCHASE170,305.000
71CURRENT BALANCE-438,240.000
INVOICES





what I got
ERROR MERGING.xlsm
ABCDEF
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
For me, the code does not produce the results you have shown in post 25. Here are my results:

abdo meghari.xlsm
ABCDEFG
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 PURCHASE170305
39CURRENT BALANCE-438,240.000
40
RESULT
Cell Formulas
RangeFormula
F4:F35F4=D4*E4


All I can think of is that ..
  • Something is different on your INVOICES sheet that is not shown in your mini-sheet above
    and/or
  • You have modified the code in some way that has caused the issue.

Perhaps you could upload an entire sample workbook, including the vba code to DropBox or OneDrive or Google drive etc and provide a public shared link here so that I could take a look at an actual file that is producing the incorrect results?
 
Upvote 0
here is file.
Thanks for the sample file.
The issue is that many of the values on your INVOICES sheet that look like numbers are actually text values & we don't get that distinction in XL2BB especially since those values are centre-aligned.
In particular, that is a problem in column E (Qty) as it results in my code concatenating the string values rather than adding the equivalent number values. For example, for Code 1338 there are three values "15", "2" and "2". So when my code does "15"+"2"+"2" the values concatenate to make "1522"

Try this v4 which has the code change highlighted:

Rich (BB code):
Sub Get_Results_v4()
  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
 
  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"
  wsR.UsedRange.Columns.AutoFit
End Sub
 
Upvote 0
ok That's fixed.:)
I would as about formatting
first about button it will copy copying of another button
second when fit the columns will do based on headers .
what I want prevent copy button again when run the macro every time and the autofit columns based on under headers , not headers.
 
Upvote 0
the autofit columns based on under headers , not headers.
I didn't understand this request. Can you show me an image of what currently happens and an image after you have manually adjusted columns to what you want and explain again in relation to those images?
 
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,568
Members
453,053
Latest member
Kiranm13

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