It sounds like you have a userform with 9 textboxes that you want to get information from.
This approach follows the practice above, the userform has two command buttons, an OK button and Cancel.
Code:
'in the userforms code module
Private Sub butCancel_Click()
Unload Me
End Sub
Private Sub butOK_Click()
Me.Hide
End Sub
The sub should be put in a normal module and could be structured like this
Code:
Sub mySub()
Dim value1 As Double, value2 As Double, value3 As Double
Dim value4 As Double, value5 As Double, value6 As Double
Dim value7 As Double, value8 As Double, value9 As Double
With UserForm1: Rem set preliminary values
.Caption = "Nine data point entry"
End With
UserForm1.Show: Rem point A
With UserForm1: Rem point B
value1 = Val(.TextBox1.Text)
value2 = Val(.TextBox2.Text)
' ...
value9 = Val(.TextBox9.Text)
End With
Unload UserForm1
If (value1 = 0) And (value2 = 0) And (value3 = 0) _
And (value4 = 0) And (value5 = 0) And (value6 = 0) _
And (value7 = 0) And (value8 = 0) And (value9 = 0) Then
MsgBox "user canceled"
Else
Rem your function code
End If
End Sub
At line A, and above, the userform referred to in the code is the one that the user sees.
However, the UserForm1 at line B and below, may or may not be that same one.
With a modal userform, the line UserForm1.Show will not finish executing until either the userform is hidden (by the user pressing OK) or unloaded (user presses Cancel).
If the userform is hidden, it is still there, just invisible.
If the userform is unloaded, it is done with, its gone.
At line B, either UserForm1 is the same userform (hidden=OK), the textboxes still have the values that the user entered.
or
if that userform is gone (unloaded=Cancel), UserForm1 at B is a new instance, the textboxes have their default values (normally vbNullString)
Following the code onward, we set value1, value2, ..., value9 to the values entered into the text boxes, using Val to convert from strings to numbers.
Since Val(vbNullString) = 0.
If all those values are 0, that is a hint that the user Canceled, in which case, do nothing.
If not, then process the values.
If all 0 is a possible entry, another way to test whether it was Canceled or OKed is to use the userform's Tag property.
Code:
Sub mySub2()
Dim value1 As Double, value2 As Double, value3 As Double
' ...
Dim cancelFlag as Boolean
With UserForm1: Rem set preliminary values
[COLOR="DarkRed"].Tag = "X"[/COLOR]
.Caption = "Nine data point entry"
End With
UserForm1.Show: Rem point A
With UserForm1: Rem point B
[COLOR="DarkRed"]cancelFlag = (.Tag = vbNullString)[/COLOR]
value1 = Val(.TextBox1.Text)
value2 = Val(.TextBox2.Text)
' ...
value9 = Val(.TextBox9.Text)
End With
Unload UserForm1
If cancelFlag Then
MsgBox "user canceled"
Else
Rem your function code
End If
End Sub
In this formulation, the Tag of the userform that the user sees ="X".
At point B, an OK UserForm1 (that the user saw) will have .Tag = "X",
while a new UserForm (because of Cancel) will have .Tag = vbNullString, the default value.
That is tested to see which button the user pressed.
I hope this helps.