Passing values between three subroutines

AndyTampa

Board Regular
Joined
Aug 14, 2011
Messages
186
Office Version
  1. 365
  2. 2016
Platform
  1. 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?

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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Thank you both. I've learned something new from both of you.
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,749
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top