Option Explicit
Function TinhTong(DLieu As Range, ThChieu As Range, Value_ As String) As Double
Dim sRng As Range, Rng As Range, Clls As Range, Rg0 As Range
Dim Cot As Byte
Set Rng = DLieu.Cells(1, 1).Resize(DLieu.Rows.Count)
Set sRng = Rng.Find(Value_, , xlFormulas, xlWhole)
Set Rng = ThChieu.Cells(2, 1).Resize(, ThChieu.Columns.Count)
For Each Clls In Rng
If Clls.Value <> "" And Clls.Offset(-1).Value <> "" Then
Set Rg0 = DLieu.Cells(1, 1).Resize(, DLieu.Columns.Count)
Cot = Rg0.Find(Clls.Offset(-1).Value).Column
TinhTong = TinhTong + Clls.Value * sRng.Offset(, Cot - 1)
End If
Next Clls
End Function