Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pass Variable to another Sub
Hey everyone, i need some help. I am trying to pass a variable to another
sub. I will need to pass 3-4 variables total, so if my example wont allllow for this please let me know what i need to do. I did look at other posts but was not able to find something that worked ( or i didnt know it would). Im not that knowegable in programing. Sub Wall() Dim WallEl As Single WallEl = Range("a1").Value End Sub Sub NextWall() Range("a2") = WallEl End Sub Thanks for your help in advance jared |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pass Variable to another Sub
There might be a more sophisticated way, but the way that I do it is:
Macro1: Worksheets(1).Range("IV65535") = myVar Macro2: myVar = Worksheets(1).Value Place the value of your variable some place on a worksheet that will not interfere with your code, calculations, additions or deletions. Remember that if you use the UsedRange constant that it will incorporate the cell with that value. If you are the sole user of the workbook, you could use a different sheet than the one your primary data base is on. But there might be a better way. "CSUS_CE_Student" wrote: Hey everyone, i need some help. I am trying to pass a variable to another sub. I will need to pass 3-4 variables total, so if my example wont allllow for this please let me know what i need to do. I did look at other posts but was not able to find something that worked ( or i didnt know it would). Im not that knowegable in programing. Sub Wall() Dim WallEl As Single WallEl = Range("a1").Value End Sub Sub NextWall() Range("a2") = WallEl End Sub Thanks for your help in advance jared |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pass Variable to another Sub
You can also delcare public variables. See the VBA help file for Public
Statements. "CSUS_CE_Student" wrote: Hey everyone, i need some help. I am trying to pass a variable to another sub. I will need to pass 3-4 variables total, so if my example wont allllow for this please let me know what i need to do. I did look at other posts but was not able to find something that worked ( or i didnt know it would). Im not that knowegable in programing. Sub Wall() Dim WallEl As Single WallEl = Range("a1").Value End Sub Sub NextWall() Range("a2") = WallEl End Sub Thanks for your help in advance jared |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pass Variable to another Sub
Hi Jared,
You can declare WallEl as Global variable and then can make use of its value in NextWall() subroutine: Sub Wall() Dim WallEl As Single WallEl = Range("a1").Value End Sub Sub NextWall() Range("a2").value = WallEl End Sub I believe your requirement is something different, if you need to pass 3-4 variables to a subroutine, let me know the actual code and I will help you out. Regards, Ravi On Feb 26, 6:52*pm, CSUS_CE_Student wrote: Hey everyone, * i need some help. * I am trying to pass a variable to another sub. *I will need to pass 3-4 variables total, so if my example wont allllow for this please let me know what i need to do. * I did look at other posts but was not able to find something that worked ( or i didnt know it would).. * Im not that knowegable in programing. Sub Wall() Dim WallEl As Single WallEl = Range("a1").Value End Sub Sub NextWall() Range("a2") = WallEl End Sub Thanks for your help in advance jared |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pass Variable to another Sub
Here is an alternative approach:
Sub dural() Dim s1 As String, s2 As String, s3 As String s1 = "QWERTY" s2 = "poiuy" s3 = "MJUYT" Call littleguy(s1, s2, s3) End Sub Sub littleguy(a As String, b As String, c As String) MsgBox (a & b & c) End Sub -- Gary''s Student - gsnu200770 "CSUS_CE_Student" wrote: Hey everyone, i need some help. I am trying to pass a variable to another sub. I will need to pass 3-4 variables total, so if my example wont allllow for this please let me know what i need to do. I did look at other posts but was not able to find something that worked ( or i didnt know it would). Im not that knowegable in programing. Sub Wall() Dim WallEl As Single WallEl = Range("a1").Value End Sub Sub NextWall() Range("a2") = WallEl End Sub Thanks for your help in advance jared |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pass Variable to another Sub
Or you could just pass the value to the other sub:
Option Explicit Sub Wall() Dim WallE1 as Double 'don't bother with Single WallE1 = activesheet.range("a1").value Call NextWall(someval:=WallE1) End Sub Sub NextWall(SomeVal as Double) activesheet.range("a2").value = someval End sub CSUS_CE_Student wrote: Hey everyone, i need some help. I am trying to pass a variable to another sub. I will need to pass 3-4 variables total, so if my example wont allllow for this please let me know what i need to do. I did look at other posts but was not able to find something that worked ( or i didnt know it would). Im not that knowegable in programing. Sub Wall() Dim WallEl As Single WallEl = Range("a1").Value End Sub Sub NextWall() Range("a2") = WallEl End Sub Thanks for your help in advance jared -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
pass a variable to activate | Excel Programming | |||
pass a variable to a public sub | Excel Programming | |||
Pass the variable into the sub function | Excel Programming | |||
Using Public to Pass Variable | Excel Programming | |||
How to pass variable value between macros | Excel Programming |