ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Reference to a different Sub (https://www.excelbanter.com/excel-programming/357613-re-reference-different-sub.html)

Rick Hansen

Reference to a different Sub
 
pontiy, You can't reference another sub, but you can keep the data from
that sub by declaring a Public variable. See example below. This way the
data is availble for any sub you wish to use it in.

enjoy, Rick

PS: Declare the public variable at top of UserForm Code, or in Code
Module...


Option Explicit
Public Ans as Variant

Private Sub CommandButton1_Click()

Ans = InPutBox(prompt:="What is your answer?")
.....
End Sub

Private Sub CommandButton5_Click()
Range("A1").value = Ans

End sub


"pontiy" wrote in
message ...

I'd appreciate you answering this question for me.


I have prompted the user for an input in one of my subs:
Private Sub CommandButton1_Click()

And now I need to use this data in a different sub:
Private Sub CommandButton5_Click()

How do I reference to a different sub to get my value?

Thank you.


--
pontiy
------------------------------------------------------------------------
pontiy's Profile:

http://www.excelforum.com/member.php...o&userid=32885
View this thread: http://www.excelforum.com/showthread...hreadid=528325





All times are GMT +1. The time now is 02:43 PM.

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