Hello Magmarinita,
Just place a messagebox with a question and listen to the response and take action from there...
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If MsgBox("Save data?", vbYesNo, "Save data?") = vbYes Then
'save thedata somewhere... See below...
MsgBox "Data has been saved.", vbOKOnly, "Success"
End If
Me.Hide
End Sub
Now it depends what you mean with save the data...
If you are going to "save it" in the sense that you want to use it directly in your code then you could either just assign the data to a global variable, or you can access the form data later by referring to theuserform...
' In the form code
somevariable = me.Textbox1.value
'outside the form code
somevariable = someuserform.Textbox1.value
if you are going to save it temporarily somewhere to pick it up later, you could just save it in a cell somewhere
someworksheet.cells(somerow,somecolumn) = me.Textbox1.value
if you want to save the data, like statistics, you could save it in a listobject, a table...
set somelistrow = somelistobject.listrows.add
somelistobject.listcolumn("somecolumnname").databodyrange(somelistrow.index) = me.Textbox1.value
Hopefully this guide you in the right direction.
Bookmarks