hello
I want some help about this code. the code collect the data from all sheets into sheet SUMMARY but my problem if repeat some data in sheet (sales,pur,returns )
it doesn't sum duplicat data.I highlighted the wrong values for some repeted data in sheet (sales,pur,returns ) which show in sheet summary and highlighted the repeated data from three sheets
theses values are not right(100,55,10). the right values should be 200, 110,21)
so it should summing duplicates values
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 xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End With
End With
Application.ScreenUpdating = True
End Sub
any help ,please?