modified code peter_SSs (copy multiple columns across multiple sheets and calculate)

abdo meghari

Well-known Member
Joined
Aug 3, 2021
Messages
651
Office Version
  1. 2019
hi experts
after long time I've found this thread copy multiple columns and matched from multiple sheets to sheet summary and calculate the code for mr @Peter_SSs and it 's soon from my requirements . I hope from him or any body has knowladge to mod the code .
VBA Code:
Sub CollateData_v2()
  Dim d As Object
  Dim ShList As Variant, a As Variant, vals As Variant
  Dim i As Long, j As Long
  Dim s As String
 
  Set d = CreateObject("Scripting.Dictionary")
  ShList = Split("stock|sales|pur|returns", "|")
  For j = 0 To UBound(ShList)
    With Sheets(ShList(j))
      a = .UsedRange.Value2
      For i = 2 To UBound(a)
        s = Join(Application.Index(a, i, Array(2, 3, 4)), ";")
        If Len(s) > 2 Then
          If Not d.exists(s) Then d(s) = ";;;"
          vals = Split(d(s), ";")
          vals(j) = a(i, 5)
          d(s) = Join(vals, ";")
        End If
      Next i
    End With
  Next j
  Application.ScreenUpdating = False
  With Sheets("summary")
    .UsedRange.EntireRow.Delete
    With .Range("B2:C2").Resize(d.Count)
      .Value = Application.Transpose(Array(d.Keys, d.Items))
      With .Columns(2)
        .TextToColumns DataType:=xlDelimited, ConsecutiveDelimiter:=False, Semicolon:=True, Comma:=False, Space:=False, Other:=False
        With .Offset(, 4)
          .FormulaR1C1 = "=RC[-4]-RC[-3]+RC[-2]+RC[-1]"
          .Value = .Value
        End With
        .Resize(, 2).EntireColumn.Insert
      End With
      .Columns(1).TextToColumns DataType:=xlDelimited, ConsecutiveDelimiter:=False, Semicolon:=True, Comma:=False, Space:=False, Other:=False
      With .Columns(0)
        .Cells(1).Value = 1
        .DataSeries Rowcol:=xlColumns, Type:=xlLinear, Step:=1
      End With
    End With
    With .Range("A1:I1")
      .Value = Array("item", "BRAND", "TYPE", "MONAFACTURE", "STOCK", "SALES", "PUR", "RETURNS", "BALANCE")
      .Font.Bold = True
  .Interior.Color = RGB(166, 166, 166)
      .EntireColumn.AutoFit
    End With
    With .UsedRange
      .BorderAround LineStyle:=xlContinuous
      .Borders(xlInsideVertical).LineStyle = xlContinuous
      .Borders(xlInsideHorizontal).LineStyle = xlContinuous
    End With
  End With
  Application.ScreenUpdating = True
End Sub

so I have many data almost the same structure the expected result in sheet INVENTORY should create whole data (headers,borders,formatting)
as you see the sheets(buying,selling,selling return,buying return) contain repeated data but different dates except sheet STOCK doesn't duplicates. when merge duplicates items should be based on COL B and summing values just column contain QTY across multiple sheets with note the duplicate item repeate for all sheets except sheet STOCK . about sheet INVENTORY QTY I put
the formula how should calculatein COL K . as to buying price , selling price should calculate average as show in sheet INVENTORY in column L,M based on only sheets(stock,buying , selling ) .about column NET calculates basd on COL(K,L,M) i put the formula how should calculate with considering when run macro repeatedly should replace the data in sheet inventory like updating
last thing I have two notes . first the formulas should show as value. second my data are big always are from 4000: 6000 rows across multiple sheets . but this is just simple data to ubderstand me
note: when create data in sheet INVENTORY should be based on sheets names (stock,buying,selling,selling returns,buying returns)
PRICE.xlsm
ABCDEFGH
1ITEMBATCHBRANDTYPEORIGINQTYBYUING PRICESELLING PRICE
21BSJ-1200G11200R20G580JAP220.00$425.00$450.00
32BSJ-1200G21200R20G580JAP300.00$422.00$455.00
43BSJ-1200G31200R20R187JAP350.00$430.00$456.00
54BSJ-1200G41200R20R187THI200.00$430.00$444.00
65BSJ-1224G51200R24G580JAP140.00$650.00$700.00
76BSJ-1400V11400R20VSJJAP140.00$780.00$850.00
87BSJ-1400V21400R20R180JAP-$880.00$890.00
STOCK



PRICE.xlsm
ABCDEFGHIJ
1DATEBATCHCUSTOMER NOINVOICE NOBRANDTYPEORIGINQTYBYUING PRICETOTAL
202/01/2021BSJ-1200G1ALL-BST1-00IN-BSJT/2-001200R20G580JAP2,000.00$423.00$846,000.00
302/02/2021BSJ-1200G1ALL-BST1-01IN-BSJT/2-011200R20G580JAP100.00$433.00$43,300.00
402/03/2021BSJ-1200G1ALL-BST1-02IN-BSJT/2-021200R20G580JAP50.00$430.00$21,500.00
502/04/2021BSJ-1200G4ALL-BST1-01IN-BSJT/2-011200R20R187THI120.00$433.00$51,960.00
602/05/2021BSJ-1224G5ALL-BST1-02IN-BSJT/2-021200R24G580JAP300.00$600.00$180,000.00
702/06/2021BSJ-1400V1ALL-BST1-02IN-BSJT/2-021400R20VSJJAP20.00$770.00$15,400.00
802/07/2021BSJ-1400V2ALL-BST1-03IN-BSJT/2-031400R20R180JAP200.00$800.00$160,000.00
902/08/2021BSJ-1400V2ALL-BST1-04IN-BSJT/2-041400R20R180JAP100.00$820.00$82,000.00
BUYING
Cell Formulas
RangeFormula
J2:J9J2=I2*H2


PRICE.xlsm
ABCDEFGHIJ
1DATEBATCHCUSTOMER NOINVOICE NOBRANDTYPEORIGINQTYSELLING PRICETOTAL
203/01/2021BSJ-1200G1CCSL-BST1-00IN-BSJT/2-001200R20G580JAP100.00$470.00$47,000.00
303/02/2021BSJ-1200G1CCSL-BST1-01IN-BSJT/2-011200R20G580JAP20.00$475.00$9,500.00
403/03/2021BSJ-1200G1CCSL-BST1-02IN-BSJT/2-021200R20G580JAP30.00$465.00$13,950.00
504/04/2021BSJ-1200G4CCSL-BST1-01IN-BSJT/2-011200R20R187THI50.00$466.00$23,300.00
604/05/2021BSJ-1224G5CCSL-BST1-02IN-BSJT/2-021200R24G580JAP60.00$710.00$42,600.00
SALLING
Cell Formulas
RangeFormula
J2:J6J2=I2*H2


PRICE.xlsm
ABCDEFGHIJ
1DATEBATCHCUSTOMER NOINVOICE NOBRANDTYPEORIGINQTYBYUING PRICETOTAL
205/01/2021BSJ-1200G1RRSL-BST1-00IN-BSJT/2-001200R20G580JAP10.00$470.00$4,700.00
305/02/2021BSJ-1200G1RRSL-BST1-01IN-BSJT/2-011200R20G580JAP20.00$475.00$9,500.00
405/03/2021BSJ-1200G1RRSL-BST1-02IN-BSJT/2-021200R20G580JAP15.00$475.00$7,125.00
SALLING RETURN
Cell Formulas
RangeFormula
J2:J4J2=I2*H2


PRICE.xlsm
ABCDEFGHIJ
1DATEBATCHCUSTOMER NOINVOICE NOBRANDTYPEORIGINQTYBYUING PRICETOTAL
205/03/2021BSJ-1200G1RRB-BST1-02IN-BSJT/2-021200R20G580JAP10.00$423.00$4,230.00
305/04/2021BSJ-1400V2RRB-BST1-03IN-BSJT/2-031400R20R180JAP20.00$800.00$16,000.00
405/05/2021BSJ-1400V2RRB-BST1-04IN-BSJT/2-041400R20R180JAP20.00$800.00$16,000.00
BUYING RETURN
Cell Formulas
RangeFormula
J2:J4J2=I2*H2


expected result
PRICE.xlsm
ABCDEFGHIJKLMN
1ITEMBATCHBRANDTYPEORIGINSTOCKBUYINGSALLINGSALLING RETURNBUYING RETURNQTYBUYING PRICESALLING PRICENET
21BSJ-1200G11200R20G580JAP220.002,150.00150.0045.0010.002,255.00$427.75$465.00$83,998.75
32BSJ-1200G21200R20G580JAP300.00----300.00$422.00$455.00$9,900.00
43BSJ-1200G31200R20R187JAP350.00----350.00$430.00$456.00$9,100.00
54BSJ-1200G41200R20R187THI200.0012050--270.00$431.50$455.00$6,345.00
65BSJ-1224G51200R24G580JAP140.0030060--380.00$625.00$705.00$30,400.00
76BSJ-1400V11400R20VSJJAP140.0020---160.00$775.00$850.00$12,000.00
87BSJ-1400V21400R20R180JAP-300--40260.00$810.00$890.00$20,800.00
INVENTORY
Cell Formulas
RangeFormula
K2:K8K2=F2+G2-H2+I2-J2
N2:N8N2=(M2-L2)*K2

the stars shows in images are short word JAPAN(JAP) but it shows *** when use XL2BB
I hope some body help
 
Last edited by a moderator:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,224,817
Messages
6,181,144
Members
453,021
Latest member
Justyna P

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