Private Sub Stock_quantity()
Dim sForm As String, sForm1 As String, Ur As Long, Ur1 As Long, Ur2 As Long, Ur3 As Long, Ur4 As Long
Dim Qt1 As Single, Qt2 As Single, Qt3 As Single, Qt4 As Single, Qt5 As Single, Qt6 As Single, Qt7 As Single, Qt8 As Single
Dim ShtC As Worksheet, ShtSI As Worksheet, ShtS2 As Worksheet, ShtS3 As Worksheet, ShtS4 As Worksheet
Set ShtC = ThisWorkbook.Worksheets("Sheet3")
Ur = ShtC.Range("D" & Rows.Count).End(xlUp).Row
Qt1 = Application.WorksheetFunction.SumIfs(ShtC.Range("H2:H" & Ur), ShtC.Range("D2:D" & Ur), Me.ComboBox3.Value, _
ShtC.Range("J2:J" & Ur), Me.ComboBox1.Value, ShtC.Range("I2:I" & Ur), "The first period")
Set ShtSI = ThisWorkbook.Worksheets("Transfer between stores")
Ur1 = ShtSI.Range("E" & Rows.Count).End(xlUp).Row
Qt2 = Application.WorksheetFunction.SumIfs(ShtSI.Range("I2:I" & Ur1), ShtSI.Range("E2:E" & Ur1), Me.ComboBox3.Value, _
ShtSI.Range("D2:D" & Ur1), Me.ComboBox1.Value, ShtSI.Range("C2:C" & Ur1), "Cashing")
Qt3 = Application.WorksheetFunction.SumIfs(ShtSI.Range("I2:I" & Ur1), ShtSI.Range("E2:E" & Ur1), Me.ComboBox3.Value, _
ShtSI.Range("J2:J" & Ur1), Me.ComboBox1.Value, ShtSI.Range("C2:C" & Ur1), "addition")
Set ShtS2 = ThisWorkbook.Worksheets("Purchases")
Ur2 = ShtS2.Range("F" & Rows.Count).End(xlUp).Row
Qt4 = Application.WorksheetFunction.SumIfs(ShtS2.Range("J2:J" & Ur2), ShtS2.Range("F2:F" & Ur2), Me.ComboBox3.Value, _
ShtS2.Range("D2:D" & Ur2), Me.ComboBox1.Value, ShtS2.Range("C2:C" & Ur2), "buy")
Qt7 = Application.WorksheetFunction.SumIfs(ShtS2.Range("J2:J" & Ur2), ShtS2.Range("F2:F" & Ur2), Me.ComboBox3.Value, _
ShtS2.Range("D2:D" & Ur2), Me.ComboBox1.Value, ShtS2.Range("C2:C" & Ur2), "Purchase return")
Set ShtS3 = ThisWorkbook.Worksheets("sales")
Ur3 = ShtS3.Range("E" & Rows.Count).End(xlUp).Row
Qt5 = Application.WorksheetFunction.SumIfs(ShtS3.Range("I2:I" & Ur3), ShtS3.Range("E2:E" & Ur3), Me.ComboBox3.Value, _
ShtS3.Range("D2:D" & Ur3), Me.ComboBox1.Value, ShtS3.Range("C2:C" & Ur3), "sale")
Qt8 = Application.WorksheetFunction.SumIfs(ShtS3.Range("I2:I" & Ur3), ShtS3.Range("E2:E" & Ur3), Me.ComboBox3.Value, _
ShtS3.Range("D2:D" & Ur3), Me.ComboBox1.Value, ShtS3.Range("C2:C" & Ur3), "Sale returns")
Set ShtS4 = ThisWorkbook.Worksheets("Transfer between stores")
Ur4 = ShtS4.Range("E" & Rows.Count).End(xlUp).Row
Qt6 = Application.WorksheetFunction.SumIfs(ShtS4.Range("I2:I" & Ur4), ShtS4.Range("E2:E" & Ur4), Me.ComboBox3.Value, _
ShtS4.Range("J2:J" & Ur4), Me.ComboBox1.Value, ShtS4.Range("C2:C" & Ur4), "Cashing")
Me.TextBox7.Value = Qt1 + Qt3 + Qt4 - Qt2 - Qt5 + Qt6 + Qt7 + Qt8
Set ShtSI = Nothing: Set ShtC = Nothing: Set ShtS2 = Nothing: Set ShtS3 = Nothing: Set ShtS4 = Nothing
End Sub