Sub TestInputBox()
Dim ws As Worksheet: Set ws = Sheets("Sheet2")
Title = Range("L1")
INPUT_VALUE:
ws.Range("C2:C6").ClearContents
tempKB = Application.InputBox(Range("L2"), Title)
If tempKB = False Then GoTo Thoat 'khi dung` Cancel
ws.Cells(2, 3).Value = tempKB
tempA1 = Application.InputBox(Range("L3"), Title)
If tempA1 = False Then GoTo Thoat
ws.Cells(3, 3).Value = tempA1
tempA2 = Application.InputBox(Range("L4"), Title)
If tempA2 = False Then GoTo Stop1
ws.Cells(4, 3).Value = tempA2
tempA3 = Application.InputBox(Range("L5"), Title)
If tempA3 = False Then GoTo Stop1
ws.Cells(5, 3).Value = tempA3
Stop1:
If IsNumeric(tempA1) = True Or IsNumeric(tempA2) = True Or IsNumeric(tempA3) = True Then
QUESTION:
answer = Application.InputBox(Range("L7") & vbNewLine & Range("L8") & vbNewLine & Range("L9"))
If UCase(answer) = "A" Then
GoTo CALCULATE
ElseIf UCase(answer) = "B" Then
GoTo INPUT_VALUE
Else
GoTo QUESTION 'hoac goto Thoat 'khi dung` Cancel
End If
Else
GoTo Stop2
End If
CALCULATE:
If tempA3 = False Then
ws.Cells(6, 3).Value = 1 + 2 * tempA1 + 3 * tempA2
ElseIf temA2 = False Then
ws.Cells(6, 3).Value = 1 + 2 * tempA1
Else
ws.Cells(6, 3).Value = 1 + 2 * tempA1 + 3 * tempA2 + 4 * tempA3
End If
Stop2:
MsgBox ("TestInputBox xong")
Set ws = Nothing
Exit Sub
Thoat:
ws.Range("C2:C6").ClearContents
Set ws = Nothing
End Sub