Hello
I need help from experts to fix mismatch error in this line
this case occures when there is new item in one of sheet and not in existed in others.
the code will bring data for all of the sheets and sum the values for columns SALE,RET for each sheet
can anybody find out how fixing the code or reproduce again ,please?
thanks
I need help from experts to fix mismatch error in this line
VBA Code:
Dic(j) = Split(Dic(j), ";")(0) + SALE & ";" & Split(Dic(j), ";")(1) + RET
the code will bring data for all of the sheets and sum the values for columns SALE,RET for each sheet
VBA Code:
Sub test()
Dim ws As Worksheet, a, Dic As Object, j$, k$, SALE As Double, RET As Double
Set Dic = CreateObject("scripting.dictionary")
For Each ws In Sheets
If ws.Name <> "COLLECTION" Then
a = ws.[A1].CurrentRegion
For x = 2 To UBound(a)
j = Join(Array(a(x, 2), a(x, 3), a(x, 4)), ";")
If UBound(a, 2) = 5 Then
If Not IsNumeric(a(x, 5)) Then a(x, 5) = 0
If a(1, 5) = "SALE" Then SALE = a(x, 5) Else RET = a(x, 5)
Else
If Not IsNumeric(a(x, 5)) Then a(x, 5) = 0
If Not IsNumeric(a(x, 6)) Then a(x, 6) = 0
SALE = IIf(a(1, 5) = "SALE", a(x, 5), a(x, 6))
RET = IIf(a(1, 5) = "SALE", a(x, 6), a(x, 5))
End If
k = Join(Array(SALE, RET), ";")
If Not Dic.exists(j) Then Dic.Add j, k Else _
Dic(j) = Split(Dic(j), ";")(0) + SALE & ";" & Split(Dic(j), ";")(1) + RET
SALE = 0: RET = 0
Next
End If
Next
With Sheets("COLLECTION").[A1].Resize(Dic.Count)
.Parent.UsedRange.Clear
.Resize(1, 7) = [{"ITEM","BR","TY","OR","SALE","RET","BALANCE"}]
.Offset(1, 1) = Application.Transpose(Dic.keys)
.Offset(1, 4) = Application.Transpose(Dic.items)
.Offset(1, 1).TextToColumns .Offset(1, 1), semicolon:=True
.Offset(1, 4).TextToColumns .Offset(1, 4), semicolon:=True
.Offset(1, 0) = Evaluate("row(1:" & Dic.Count & ")")
.Offset(1, 6) = "=E2-F2"
.Offset(1, 6) = .Offset(1, 6).Value
.Offset(1, 4).Resize(, 3).NumberFormat = "#,0;[red]-#,0;-"
.Resize(Dic.Count + 1, 7).Borders.LineStyle = 1
End With
End Sub
thanks