I am trying to write a userform yes/no code.?

Its a before close code. If a particular cell has a value of zero, the userform appears asking the person "are you sure the value is 0". If he clicks yes, then the document should close. if he clicks no, sheet2 should activate and the document should not close. The problem with my code is that even when i click no, the document closes. The reason that im not using msgbox is that this userfom is supposed to be in french and messagebox doesnot give yes/no in french.

My code is

'in the workbook window:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

If Worksheets("sheet1").Range("H15").Value = 0 Then

box.Show

'box is the name of the userform

End If

End Sub

'in the userform window:

'when the userform clicks No

Private Sub N_Click()

MsgBox ("fill all")

Sheets("sheet2").Activate

Unload Me

End Sub

'when yes is clicked

Private Sub Y_Click()

MsgBox ("thanks")

Me.Hide

End Sub

Sign In or Register to comment.