Excel · मराठी आवृत्ती
12.8 MsgBox आणि InputBox
या page मध्ये
MsgBox message/choice दाखवतो. InputBox userकडून value मागतो.
Sub AskCity()
Dim city As String
Dim answer As VbMsgBoxResult
city = InputBox("Enter city name (e.g. Pune):", "Blinkit Report", "Pune")
If city = "" Then Exit Sub ' user pressed Cancel or left it empty
answer = MsgBox("Create report for " & city & "?", vbYesNo + vbQuestion, "Confirm")
If answer = vbYes Then
MsgBox "Report for " & city & " will be created.", vbInformation
Else
MsgBox "Cancelled.", vbExclamation
End If
End Sub
Source example फक्त confirmation message दाखवतो; actual report तयार करणारा code यात नाही. InputBox Cancel किंवा empty entryसाठी empty string देतो; आधी check करून Exit Sub करा.
| Constants | उपयोग |
|---|---|
| vbOKOnly, vbYesNo, vbYesNoCancel, vbOKCancel | Buttons. |
| vbInformation, vbQuestion, vbExclamation, vbCritical | Icon. |
| vbYes, vbNo, vbCancel, vbOK | काय click झालं ते result. |
Numeric input
Dim result As Variant
result = Application.InputBox("Enter minimum amount", Type:=1)
If VarType(result) = vbBoolean Then
If result = False Then Exit Sub
End If
If result < 0 Then
MsgBox "Amount must be non-negative."
Exit Sub
End IfApplication.InputBox Type 1 number घेतो; Cancelला Boolean False मिळतो. Numeric 0 आणि Cancel गोंधळू नयेत म्हणून Variantचा type तपासा. Type 8 Range selectionसाठी; Range object assign करताना Set आणि Cancel handling लागते.
Practice
Minimum Amount input घेऊन त्यापेक्षा जास्त Amount असलेल्या rowsचा CountIf result Information MsgBoxमध्ये दाखवा. Cancel, 0, negative आणि valid positive input तपासा.