hi
after many tries to mod the code I need fixing somethings I try to match data based on column B instead columns B,C,D,E as in my case and the values after calculate should show in column J but it shows in column K and there is empty row shows as in row 18
I hope some body helps me to fix theses problems
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, 5)), ";")
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, 6)
Else
vals(j) = a(i, 6)
End If
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(, 5)
.FormulaR1C1 = "=RC[-4]-RC[-3]+RC[-2]+RC[-1]"
.Value = .Value
End With
.Resize(, 3).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:J1")
.Value = Array("item", "CODE", "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