I guess you're having that error upon clicking the "Close" button (the "X" in the upper-right corner), and that expence is the name of your userform.
in order to prevent the user closing the userform with the "X" button add the following code in your userform code pane
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
MsgBox "Click the proper button to close the form" '<--| you may want to substitute "proper" with the actual caption of the button you want the user click to exit the userform
Cancel = True
End If
End Sub
furthermore you have to properly exit the userform, that can be usually done by:
having the parent sub load, show and close the userform like follows:
Sub main() ' your sub that cals 'expence' userform
' ... possible code preceeding 'expence' useform exploitation
With expence '<--| this loads the Userform and trigger its 'UserForm_Initialize()' event handler, too
' ... possible code for some userform controls values initializations not left to 'UserForm_Initialize()'
.ComboBox1.List = Array(1, 2, 3, 4)
.Show '<--| this actually makes the userform visible in the screen
' ... possible code for some userform controls values exploitations not already done in its "farewell" event handler ('CommandButton1_Click()' in this case)
End With
Unload expence '<--| this finally "closes" the userfom
' ... possible code following 'expence' useform exploitation
End Sub
having the useform "farewell" sub just hide the userform itself
Private Sub CommandButton1_Click() '<--| thi is tha "farewell" sub, i.e. the one that uses the 'Hide' method of the Userform class to have the user leave the userform
Dim blankrow As Long '<--| better use "Long" type variables instead of integers and handle row index greater that 32k or so
Dim ws As Worksheet: Set ws = Worksheets("Data_Base")
blankrow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
With Me '<--| "me" actually refers to the Useform itself. this way you benefit from 'Intellisense' and have your control names available after typing the "dot" (".")
ws.Cells(blankrow, 1) = Format(.TextDate.Value, "mm/dd/yyyy")
ws.Cells(blankrow, 2) = .ComboBox1
ws.Cells(blankrow, 3) = Format(.TextPrice.Value, "General number")
.TextboxTotal.Text = ws.Range("F2")
.TextDate.Value = ""
.ComboBox1.Value = ""
.TextPrice.Value = ""
.Hide '<--| this just hides the userfom from the screen, leaving its actual "closing" to the caller sub
End With
End Sub
expense.showin theUserForm_Initialize, but at another routine that calls the this routine.