make a variable retain its value after userform closes :: MrExcel Message Board


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

make a variable retain its value after userform closes
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

DRJ
Board Master
Board  Master


Joined: 18 Feb 2002
Posts: 1022
Location: California
Flag: Usa

Status: Offline

 Reply with quote  

make a variable retain its value after userform closes

Is there a way to make a variable retain its value until a new value is assigned to it? Like if you assign a variable a value from a userform then unload the form the variable will be =0, can it just retain the value indefinately. I want other userforms, subroutines to be able to get this value. Currently I just drop the value into a cell on a worksheet, but was looking for another way.

Thanks

Post Sat Sep 20, 2003 3:06 am 
 View user's profile Send private message Send e-mail

HalfAce
Board Master


Joined: 07 Apr 2003
Posts: 685
Location: Cordova, Alaska
Flag: Blank

Status: Offline

 Reply with quote  

Re: make a variable retain its value after userform closes

Hi DRJ,
I'm not positive I'm following you completely. Do you mean you want a variable (that's it a textbox) in your userform to still be there next time you call up the userform?

By "Currently I just drop the value into a cell on a worksheet" do you mean you have that cell as the Control source for the textbox?

I'm thinking that if you use "UserForm1.Hide" instead of unloading it your variable will still be there next time you open the userform. (At least it works that way for me with the following.)

code:


Private Sub Test()
If TextBox1.Value <> "" Then
[E1].Value = TextBox1.Value
[E1].Copy
[F1].Select
ActiveSheet.Paste
End If
UserForm1.Hide
End Sub




Now if I hit the button that calls up the userform, the number I entered in there the last time is still there without a linked cell.

Does this help at all?
HalfAce

Post Sat Sep 20, 2003 4:32 am 
 View user's profile Send private message

DRJ
Board Master
Board  Master


Joined: 18 Feb 2002
Posts: 1022
Location: California
Flag: Usa

Status: Offline

 Reply with quote  

Re: make a variable retain its value after userform closes

Basically what I have is several date fields on various forms. I have a seperate userform with a calendar control on it, and when a date is selected I want to put that date into the field on the original form. What I wanted was to keep the value of the date after the date userform is closed, so that when I return to the original subroutine it can input the value into the appropriate field and the appropriate userform. So what I do it put the value into say "A1" on sheet 1 and then get the value from there. I was just wondering if there was a way to keep the value in memory longer.

Thanks

Post Sat Sep 20, 2003 5:11 am 
 View user's profile Send private message Send e-mail
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.