#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Programming

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Programming [email protected] New Users to Excel 2 May 28th 08 08:38 PM
New to Programming Anice Excel Programming 5 June 8th 06 06:02 PM
Programming to VBE Ron de Bruin Excel Programming 1 September 15th 04 07:51 PM
Programming lag Ernst Guckel[_3_] Excel Programming 4 June 9th 04 03:40 PM
Programming lag.. Ernst Guckel[_3_] Excel Programming 0 June 8th 04 03:37 AM


All times are GMT +1. The time now is 08:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"