change code match data based on one column instead of three columns

leap out

Active Member
Joined
Dec 4, 2020
Messages
288
Office Version
  1. 2016
  2. 2010
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
INVEN v0 a.xlsm
ABCDEFGH
1itemID CUS NOINV NOBRANDTYPEMONAFACTUREQTY
21ASDK-12CC-1IN12310W40 208LQ8EU2222
32ASDK-13CC-2IN12415W40 208LCASSU400
43ASDK-14CC-3IN1255W30 208LQ8EU800
54ASDK-15CC-4IN1265W30 12x1LQ8EU600
65ASDK-16CC-5IN12710W40 208LENIIT300
76ASDK-17CC-6IN1285W30 4x4LQ8EU200
87ASDK-18CC-7IN12910W40 12x1LQ8EU120
98ASDK-19CC-8IN13015W40 12x1LCASSU450
109ASDK-20CC-9IN13110W40 12x1LENIIT890
1110ASDK-21CC-10IN13210W40 4x4LQ8EU345
1211ASDK-22CC-11IN13310W40 4x4LCASSU78
1312ASDK-23CC-12IN13410W40 4x4LENIIT123
1413ASDK-24CC-13IN1355W40 4x4LQ8EU456
1514ASDK-25CC-14IN1365W40 4x4LCASSU678
1615ASDK-26CC-15IN1375W40 4x4LENIIT1234
1716ASDK-27CC-16IN13820W50 4x4LQ8EU456
stock





INVEN v0 a.xlsm
ABCDEFGH
1DATEID CUS NOINV NOBRANDTYPEMONAFACTURESALES
201/01/2021ASDK-12CC-1IN12310W40 208LQ8EU100
302/01/2021ASDK-13CC-2IN12415W40 208LCASSU50
403/01/2021ASDK-14CC-3IN1255W30 208LQ8EU280
504/01/2021ASDK-15CC-4IN1265W30 12x1LQ8EU300
605/01/2021ASDK-16CC-5IN12710W40 208LENIIT80
706/01/2021ASDK-17CC-6IN1285W30 4x4LQ8EU20
807/01/2021ASDK-18CC-7IN12910W40 12x1LQ8EU20
908/01/2021ASDK-19CC-8IN13015W40 12x1LCASSU20
1009/01/2021ASDK-20CC-9IN13110W40 12x1LENIIT876
1110/01/2021ASDK-21CC-10IN13210W40 4x4LQ8EU345
1211/01/2021ASDK-22CC-11IN13310W40 4x4LCASSU123
1312/01/2021ASDK-23CC-12IN13410W40 4x4LENIIT78
1413/01/2021ASDK-24CC-13IN1355W40 4x4LQ8EU300
1514/01/2021ASDK-25CC-14IN1365W40 4x4LCASSU34
1615/01/2021ASDK-26CC-15IN1375W40 4x4LENIIT23
1716/01/2021ASDK-27CC-16IN13820W50 4x4LQ8EU56
1817/01/2021ASDK-12CC-17IN13910W40 208LQ8EU100
sales



INVEN v0 a.xlsm
ABCDEFGH
1DATEID CUS NOINV NOBRANDTYPEMONAFACTUREPURCHASE
204/02/2021ASDK-12CC-1IN12310W40 208LQ8EU55
305/02/2021ASDK-13CC-2IN12415W40 208LCASSU20
406/02/2021ASDK-14CC-3IN1255W30 208LQ8EU10
507/02/2021ASDK-15CC-4IN1265W30 12x1LQ8EU10
608/02/2021ASDK-16CC-5IN12710W40 208LENIIT3
709/02/2021ASDK-17CC-6IN1285W30 4x4LQ8EU4
810/02/2021ASDK-18CC-7IN12910W40 12x1LQ8EU45
911/02/2021ASDK-19CC-8IN13015W40 12x1LCASSU8
1012/02/2021ASDK-20CC-9IN13110W40 12x1LENIIT1
1113/02/2021ASDK-21CC-10IN13210W40 4x4LQ8EU100
1214/02/2021ASDK-22CC-11IN13310W40 4x4LCASSU20
1315/02/2021ASDK-23CC-12IN13410W40 4x4LENIIT100
1416/02/2021ASDK-24CC-13IN1355W40 4x4LQ8EU44
1517/02/2021ASDK-25CC-14IN1365W40 4x4LCASSU20
1618/02/2021ASDK-26CC-15IN1375W40 4x4LENIIT50
1719/02/2021ASDK-27CC-16IN13820W50 4x4LQ8EU12
1820/02/2021ASDK-28CC-17IN13920W50 4x4LCASSU9
1921/02/2021ASDK-29CC-18IN14020W50 4x4LENIIT4
2022/02/2021ASDK-12CC-19IN14110W40 208LQ8EU55
pur



INVEN v0 a.xlsm
ABCDEFGH
1itemID CUS NOINV NOBRANDTYPEMONAFACTUREreturns
205/04/2021ASDK-20CC-9IN13110W40 12x1LENIIT20
306/04/2021ASDK-22CC-11IN13310W40 4x4LQ8EU30
407/04/2021ASDK-23CC-12IN13410W40 4x4LCASSU40
508/04/2021ASDK-15CC-4IN1355W30 12x1LQ8EU10
609/04/2021ASDK-15CC-5IN1365W30 12x1LQ8EU11
returns


INVEN v0 a.xlsm
ABCDEFGHIJ
1itemIDBRANDTYPEMONAFACTURESTOCKSALESPURRETURNSBALANCE
21ASDK-1210W40 208LQ8EU22222001102132
32ASDK-1315W40 208LCASSU4005020370
43ASDK-145W30 208LQ8EU80028010530
54ASDK-155W30 12x1LQ8EU6003001021331
65ASDK-1610W40 208LENIIT300803223
76ASDK-175W30 4x4LQ8EU200204184
87ASDK-1810W40 12x1LQ8EU1202045145
98ASDK-1915W40 12x1LCASSU450208438
109ASDK-2010W40 12x1LENIIT89087612035
1110ASDK-2110W40 4x4LQ8EU34534510030130
1211ASDK-2210W40 4x4LCASSU78123204015
1312ASDK-2310W40 4x4LENIIT12378100145
1413ASDK-245W40 4x4LQ8EU45630044200
1514ASDK-255W40 4x4LCASSU6783420664
1615ASDK-265W40 4x4LENIIT123423501261
1716ASDK-2720W50 4x4LQ8EU4565612412
1817ASDK-2820W50 4x4LCASSU99
1918ASDK-2920W50 4x4LENIIT44
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
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,224,752
Messages
6,180,742
Members
452,996
Latest member
nelsonsix66

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