AndyTampa
Board Regular
- Joined
- Aug 14, 2011
- Messages
- 199
- Office Version
- 365
- 2016
- Platform
- Windows
I'm trying to pass a value between subs that can be used by other subs. I was able to pass a value to one sub, but since I may get that value to use in a few subs, I created a subroutine to get that value. But it won't get the value and pass it to the main macro.
In this macro, I want to run the subroutine LastRow to get the last row of data and pass that value to MAIN. Then I want MAIN to pass the value to TWO. I want to be able to use both LastRow and TWO in other macros too. When I put the entire LastRow code into MAIN, the variable is passed to TWO without a problem. How can I get LastRow to pass the variable to MAIN first?
In this macro, I want to run the subroutine LastRow to get the last row of data and pass that value to MAIN. Then I want MAIN to pass the value to TWO. I want to be able to use both LastRow and TWO in other macros too. When I put the entire LastRow code into MAIN, the variable is passed to TWO without a problem. How can I get LastRow to pass the variable to MAIN first?
VBA Code:
Sub MAIN()
Dim LRow As Long
LastRow (LRow)
TWO (LRow)
'a whole bunch of stuff
End Sub
-------------
Sub LastRow(LRow)
LRow = Cells.Find(What:="*", After:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
End Sub
-----------
Sub TWO(LRow)
'more stuff
End Sub