It should be in column B in the "recon" sheet which I mark yellow but I use the vba code below but the result is in column G in the sheet "recon" which I mark red. There may be something wrong in the code I edited below and I just added a little or modified it a little without changing the code structure below.

thanks

roykana

VBA Code:

```
Option Explicit
Sub SumIfs()
Dim dic As Object
Dim shs As Variant
Dim a As Variant, b As Variant, c As Variant, d As Variant
Dim i As Long, j As Long, k As Long, lr As Long, lt As Long, m As Long, n As Long
Set dic = CreateObject("Scripting.Dictionary")
shs = Array("TEST", "A")
For i = 0 To UBound(shs) Step 2
'Find the last row with data from each sheet.
lr = Sheets(shs(i)).Range(shs(i + 1) & Rows.Count).End(3).Row
'Calculate the possible total of rows, that is, the sum of the rows of all the sheets
lt = lt + lr
'Fill a matrix for each sheet
If i = 0 Then a = Sheets(shs(i)).Range("A2:G" & lr).Value
Next
'To fill everything with 0
ReDim d(1 To lt + 1, 1 To 7)
For i = 1 To UBound(d, 1)
For j = 2 To UBound(d, 2)
d(i, j) = 0
Next
Next
'OPS
For i = 1 To UBound(a, 1)
If Not dic.exists(a(i, 1)) Then
'If it is not in the dictionary, the row of the output matrix is ??increased by one
n = n + 1
'The dictionary is filled with the row number
dic(a(i, 1)) = n
'The array is filled, the value is put in the row number, column 1
d(n, 1) = a(i, 1)
End If
'Gets the row number in j
j = dic(a(i, 1))
For k = 7 To 7
'The values are added within the matrix, in row j, from column 7 to column 7
d(j, k) = d(j, k) + a(i, k)
Next
Next
'Calculate totals
k = n + 1
For i = 1 To n
For j = 2 To UBound(d, 2)
d(k, j) = d(k, j) + d(i, j)
Next
Next
Sheets("RECON").Range("A2").Resize(n + 1, UBound(d, 2)).Value = d
End Sub
```

Source

problem sumif.xlsm | |||||||||
---|---|---|---|---|---|---|---|---|---|

A | B | C | D | E | F | G | |||

1 | ITEM NO | ITEM 1 | ITC 1 | ITEM 2 | ITC 2 | QM18 | QCJR | ||

2 | 1000 | TEST R 1000 | 0-1000 | TEST RR 1000 | 0-1000-0 | 5 | 5 | ||

3 | 1001 | TEST R 1001 | 0-1001 | TEST RR 1001 | 0-1001-0 | 10 | 10 | ||

TEST |

DESIRED RESULT

problem sumif.xlsm | |||||||||
---|---|---|---|---|---|---|---|---|---|

A | B | C | D | E | F | G | |||

1 | ITEM NO | QCJR | |||||||

2 | 1000 | 0 | 0 | 0 | 0 | 0 | 5 | ||

3 | 1001 | 0 | 0 | 0 | 0 | 0 | 10 | ||

4 | 0 | 0 | 0 | 0 | 0 | 15 | |||

RECON |