ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Programming (https://www.excelbanter.com/excel-programming/396319-programming.html)

Suhas

Programming
 
How can I have user form return a value when the form closes


joel

Programming
 
One way is with a public variable. You have to change the userform type from
private to public. Then declare a vailble in the VBA module window outside
you other functions and subroutines.

"Suhas" wrote:

How can I have user form return a value when the form closes


Chip Pearson

Programming
 
Create a Public variable in the userform's code module and set that variable
when you close the form. E.g.,

"Suhas" wrote in message
...
How can I have user form return a value when the form closes



Chip Pearson

Programming
 
Create a Public variable in the userform's code module and set that variable
when you close the form. E.g.,

Public ReturnValue As Long

Private Sub btnClose_Click()
Me.ReturnValue = 123
Me.Hide
End Sub

Then, read the variable in the form with code right after you Show the
form:

Sub ShowForm()
Dim Res As Long
UserForm1.Show vbModal
Res = Userorm1.ReturnValue
Unload Userform1
MsgBox CStr(Res)
End Sub


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


"Suhas" wrote in message
...
How can I have user form return a value when the form closes




All times are GMT +1. The time now is 05:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com