hi experts
this code I got fom prevouis time by @Peter_SSs . it works so well. now I have somethings need adusting.
first instead of match data based on three columns B,C,D as in orginal code I would based on one column is B
the last sheet is expected result
this code I got fom prevouis time by @Peter_SSs . it works so well. now I have somethings need adusting.
first instead of match data based on three columns B,C,D as in orginal code I would based on one column is B
the last sheet is expected result
INVEN v0 a.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | item | ID | CUS NO | INV NO | BRAND | TYPE | MONAFACTURE | QTY | ||
2 | 1 | ASDK-12 | CC-1 | IN123 | 10W40 208L | Q8 | EU | 2222 | ||
3 | 2 | ASDK-13 | CC-2 | IN124 | 15W40 208L | CAS | SU | 400 | ||
4 | 3 | ASDK-14 | CC-3 | IN125 | 5W30 208L | Q8 | EU | 800 | ||
5 | 4 | ASDK-15 | CC-4 | IN126 | 5W30 12x1L | Q8 | EU | 600 | ||
6 | 5 | ASDK-16 | CC-5 | IN127 | 10W40 208L | ENI | IT | 300 | ||
7 | 6 | ASDK-17 | CC-6 | IN128 | 5W30 4x4L | Q8 | EU | 200 | ||
8 | 7 | ASDK-18 | CC-7 | IN129 | 10W40 12x1L | Q8 | EU | 120 | ||
9 | 8 | ASDK-19 | CC-8 | IN130 | 15W40 12x1L | CAS | SU | 450 | ||
10 | 9 | ASDK-20 | CC-9 | IN131 | 10W40 12x1L | ENI | IT | 890 | ||
11 | 10 | ASDK-21 | CC-10 | IN132 | 10W40 4x4L | Q8 | EU | 345 | ||
12 | 11 | ASDK-22 | CC-11 | IN133 | 10W40 4x4L | CAS | SU | 78 | ||
13 | 12 | ASDK-23 | CC-12 | IN134 | 10W40 4x4L | ENI | IT | 123 | ||
14 | 13 | ASDK-24 | CC-13 | IN135 | 5W40 4x4L | Q8 | EU | 456 | ||
15 | 14 | ASDK-25 | CC-14 | IN136 | 5W40 4x4L | CAS | SU | 678 | ||
16 | 15 | ASDK-26 | CC-15 | IN137 | 5W40 4x4L | ENI | IT | 1234 | ||
17 | 16 | ASDK-27 | CC-16 | IN138 | 20W50 4x4L | Q8 | EU | 456 | ||
stock |
INVEN v0 a.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | DATE | ID | CUS NO | INV NO | BRAND | TYPE | MONAFACTURE | SALES | ||
2 | 01/01/2021 | ASDK-12 | CC-1 | IN123 | 10W40 208L | Q8 | EU | 100 | ||
3 | 02/01/2021 | ASDK-13 | CC-2 | IN124 | 15W40 208L | CAS | SU | 50 | ||
4 | 03/01/2021 | ASDK-14 | CC-3 | IN125 | 5W30 208L | Q8 | EU | 280 | ||
5 | 04/01/2021 | ASDK-15 | CC-4 | IN126 | 5W30 12x1L | Q8 | EU | 300 | ||
6 | 05/01/2021 | ASDK-16 | CC-5 | IN127 | 10W40 208L | ENI | IT | 80 | ||
7 | 06/01/2021 | ASDK-17 | CC-6 | IN128 | 5W30 4x4L | Q8 | EU | 20 | ||
8 | 07/01/2021 | ASDK-18 | CC-7 | IN129 | 10W40 12x1L | Q8 | EU | 20 | ||
9 | 08/01/2021 | ASDK-19 | CC-8 | IN130 | 15W40 12x1L | CAS | SU | 20 | ||
10 | 09/01/2021 | ASDK-20 | CC-9 | IN131 | 10W40 12x1L | ENI | IT | 876 | ||
11 | 10/01/2021 | ASDK-21 | CC-10 | IN132 | 10W40 4x4L | Q8 | EU | 345 | ||
12 | 11/01/2021 | ASDK-22 | CC-11 | IN133 | 10W40 4x4L | CAS | SU | 123 | ||
13 | 12/01/2021 | ASDK-23 | CC-12 | IN134 | 10W40 4x4L | ENI | IT | 78 | ||
14 | 13/01/2021 | ASDK-24 | CC-13 | IN135 | 5W40 4x4L | Q8 | EU | 300 | ||
15 | 14/01/2021 | ASDK-25 | CC-14 | IN136 | 5W40 4x4L | CAS | SU | 34 | ||
16 | 15/01/2021 | ASDK-26 | CC-15 | IN137 | 5W40 4x4L | ENI | IT | 23 | ||
17 | 16/01/2021 | ASDK-27 | CC-16 | IN138 | 20W50 4x4L | Q8 | EU | 56 | ||
18 | 17/01/2021 | ASDK-12 | CC-17 | IN139 | 10W40 208L | Q8 | EU | 100 | ||
sales |
INVEN v0 a.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | DATE | ID | CUS NO | INV NO | BRAND | TYPE | MONAFACTURE | PURCHASE | ||
2 | 04/02/2021 | ASDK-12 | CC-1 | IN123 | 10W40 208L | Q8 | EU | 55 | ||
3 | 05/02/2021 | ASDK-13 | CC-2 | IN124 | 15W40 208L | CAS | SU | 20 | ||
4 | 06/02/2021 | ASDK-14 | CC-3 | IN125 | 5W30 208L | Q8 | EU | 10 | ||
5 | 07/02/2021 | ASDK-15 | CC-4 | IN126 | 5W30 12x1L | Q8 | EU | 10 | ||
6 | 08/02/2021 | ASDK-16 | CC-5 | IN127 | 10W40 208L | ENI | IT | 3 | ||
7 | 09/02/2021 | ASDK-17 | CC-6 | IN128 | 5W30 4x4L | Q8 | EU | 4 | ||
8 | 10/02/2021 | ASDK-18 | CC-7 | IN129 | 10W40 12x1L | Q8 | EU | 45 | ||
9 | 11/02/2021 | ASDK-19 | CC-8 | IN130 | 15W40 12x1L | CAS | SU | 8 | ||
10 | 12/02/2021 | ASDK-20 | CC-9 | IN131 | 10W40 12x1L | ENI | IT | 1 | ||
11 | 13/02/2021 | ASDK-21 | CC-10 | IN132 | 10W40 4x4L | Q8 | EU | 100 | ||
12 | 14/02/2021 | ASDK-22 | CC-11 | IN133 | 10W40 4x4L | CAS | SU | 20 | ||
13 | 15/02/2021 | ASDK-23 | CC-12 | IN134 | 10W40 4x4L | ENI | IT | 100 | ||
14 | 16/02/2021 | ASDK-24 | CC-13 | IN135 | 5W40 4x4L | Q8 | EU | 44 | ||
15 | 17/02/2021 | ASDK-25 | CC-14 | IN136 | 5W40 4x4L | CAS | SU | 20 | ||
16 | 18/02/2021 | ASDK-26 | CC-15 | IN137 | 5W40 4x4L | ENI | IT | 50 | ||
17 | 19/02/2021 | ASDK-27 | CC-16 | IN138 | 20W50 4x4L | Q8 | EU | 12 | ||
18 | 20/02/2021 | ASDK-28 | CC-17 | IN139 | 20W50 4x4L | CAS | SU | 9 | ||
19 | 21/02/2021 | ASDK-29 | CC-18 | IN140 | 20W50 4x4L | ENI | IT | 4 | ||
20 | 22/02/2021 | ASDK-12 | CC-19 | IN141 | 10W40 208L | Q8 | EU | 55 | ||
pur |
INVEN v0 a.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | item | ID | CUS NO | INV NO | BRAND | TYPE | MONAFACTURE | returns | ||
2 | 05/04/2021 | ASDK-20 | CC-9 | IN131 | 10W40 12x1L | ENI | IT | 20 | ||
3 | 06/04/2021 | ASDK-22 | CC-11 | IN133 | 10W40 4x4L | Q8 | EU | 30 | ||
4 | 07/04/2021 | ASDK-23 | CC-12 | IN134 | 10W40 4x4L | CAS | SU | 40 | ||
5 | 08/04/2021 | ASDK-15 | CC-4 | IN135 | 5W30 12x1L | Q8 | EU | 10 | ||
6 | 09/04/2021 | ASDK-15 | CC-5 | IN136 | 5W30 12x1L | Q8 | EU | 11 | ||
returns |
INVEN v0 a.xlsm | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | |||
1 | item | ID | BRAND | TYPE | MONAFACTURE | STOCK | SALES | PUR | RETURNS | BALANCE | ||
2 | 1 | ASDK-12 | 10W40 208L | Q8 | EU | 2222 | 200 | 110 | 2132 | |||
3 | 2 | ASDK-13 | 15W40 208L | CAS | SU | 400 | 50 | 20 | 370 | |||
4 | 3 | ASDK-14 | 5W30 208L | Q8 | EU | 800 | 280 | 10 | 530 | |||
5 | 4 | ASDK-15 | 5W30 12x1L | Q8 | EU | 600 | 300 | 10 | 21 | 331 | ||
6 | 5 | ASDK-16 | 10W40 208L | ENI | IT | 300 | 80 | 3 | 223 | |||
7 | 6 | ASDK-17 | 5W30 4x4L | Q8 | EU | 200 | 20 | 4 | 184 | |||
8 | 7 | ASDK-18 | 10W40 12x1L | Q8 | EU | 120 | 20 | 45 | 145 | |||
9 | 8 | ASDK-19 | 15W40 12x1L | CAS | SU | 450 | 20 | 8 | 438 | |||
10 | 9 | ASDK-20 | 10W40 12x1L | ENI | IT | 890 | 876 | 1 | 20 | 35 | ||
11 | 10 | ASDK-21 | 10W40 4x4L | Q8 | EU | 345 | 345 | 100 | 30 | 130 | ||
12 | 11 | ASDK-22 | 10W40 4x4L | CAS | SU | 78 | 123 | 20 | 40 | 15 | ||
13 | 12 | ASDK-23 | 10W40 4x4L | ENI | IT | 123 | 78 | 100 | 145 | |||
14 | 13 | ASDK-24 | 5W40 4x4L | Q8 | EU | 456 | 300 | 44 | 200 | |||
15 | 14 | ASDK-25 | 5W40 4x4L | CAS | SU | 678 | 34 | 20 | 664 | |||
16 | 15 | ASDK-26 | 5W40 4x4L | ENI | IT | 1234 | 23 | 50 | 1261 | |||
17 | 16 | ASDK-27 | 20W50 4x4L | Q8 | EU | 456 | 56 | 12 | 412 | |||
18 | 17 | ASDK-28 | 20W50 4x4L | CAS | SU | 9 | 9 | |||||
19 | 18 | ASDK-29 | 20W50 4x4L | ENI | IT | 4 | 4 | |||||
summary |
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), ";")
If IsNumeric(vals(j)) Then
vals(j) = vals(j) + a(i, 5)
Else
vals(j) = a(i, 5)
End If
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","ID", "BRAND", "TYPE", "MONAFACTURE", "STOCK", "SALES", "PUR", "RETURNS", "BALANCE")
.Font.Bold = True
.Interior.Color = RGB(166, 166, 166)
.EntireColumn.AutoFit
End With
With .UsedRange
.BorderAround xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End With
End With
Application.ScreenUpdating = True
End Sub