Anthony's VBA Forum Index Anthony's VBA Forum
Where the knowledge is shared
Menu
 Anthony's VBA Forum IndexHome Page
 Anthony's VBA Forum IndexForum Index
FAQFAQ
MemberlistMemberlist
UsergroupsUsergroups
RegisterRegister
ProfileProfile
Log in to check your private messagesMessages
Log inLogin/Out

Quick Search

Advanced Search

Links
Consulting
Products

Who's Online
[ Administrator ]
[ Moderator ]


New to VBA-Trying to store a variable

 
Post new topic   Reply to topic     Anthony's VBA Forum Index -> General Excel VBA
View previous topic :: View next topic  
Author Message
gestrich



Joined: 19 Jan 2009
Posts: 1

PostPosted: Mon Jan 19, 2009 10:48 pm    Post subject: New to VBA-Trying to store a variable Reply with quote

I am brand spanking new to VBA and am trying to figure out some of the basics of VBA. This issue will probably come as really basic to everyone except myself right now but I hope to change that in time Smile

I am trying to figure out how to store a value as a variable in VBA for later use (in a seperate sub). For example, I would like an input box request a value then store that value.

I am finding that when I store a variable, it is only "saved" while that sub is running. If I try to call that variable from another sub, it looses the value I assigned previously.

I was researching a little about static variables but I cannot get that to work either. When attempting to run the below subs, I get a blank message box. Any suggestions for how to store user data that can be called upon from other subs later?

[/code]Sub PleaseSaveData()

Static aInput

aInput = InputBox("Type the variable")

End Sub

Sub DisplayHold()

MsgBox aInput

End Sub[code]
Back to top
View user's profile Send private message
Kenneth Hobson
Gold Member
Gold Member


Joined: 25 Mar 2007
Posts: 21
Location: Tecumseh, OK

PostPosted: Mon Feb 02, 2009 2:29 pm    Post subject: Reply with quote

[code]Public aInput as String

Sub PleaseSaveData()
aInput = InputBox("Type the variable")
End Sub

Sub DisplayHold()
MsgBox aInput
End Sub[/code]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Anthony's VBA Forum Index -> General Excel VBA All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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 © 2001, 2002 phpBB Group