Option Explicit
Sub Tong()
Dim i&, j&, sR&, iR&, jC&, Nv As String
Dim Price(), Data(), tArr(), Res(), Dic As Object
With Sheets("RESULT")
tArr = .Range("E6:G6").Value
Nv = .Range("B7").Value2
End With
ReDim Res(1 To 1, 1 To 3)
With Sheets("Price")
i = .Range("A" & Rows.Count).End(xlUp).Row
If i < 3 Then MsgBox ("Khong co du lieu"): Exit Sub
Price = .Range("A3:E" & i).Value2
End With
With Sheets("DATA 1")
i = .Range("A" & Rows.Count).End(xlUp).Row
If i < 2 Then MsgBox ("Khong co du lieu"): Exit Sub
Data = .Range("A2:M" & i).Value2
End With
Set Dic = CreateObject("scripting.dictionary")
sR = UBound(Price)
For i = 1 To sR
Dic.Item(Application.Trim(Price(i, 1))) = i
Next i
For j = 1 To 3
Dic.Item(UCase(tArr(1, j))) = j
Next j
sR = UBound(Data)
For i = 1 To sR
If Data(i, 13) = Nv Then
iR = Dic.Item(Data(i, 4))
If iR > 0 Then
jC = Dic.Item(UCase(Data(i, 1)))
If jC > 0 Then
Res(1, jC) = Res(1, jC) + Data(i, 7) * Price(iR, jC + 2)
End If
End If
End If
Next i
With Sheets("RESULT")
.Range("E7:G7").Value2 = Res
End With
Set Dic = Nothing
End Sub