Setting Global Variables

30percent

Board Regular
Joined
May 5, 2011
Messages
123
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I'm trying to set global variables for final row of a region of each sheet I have. I have the following code. However, when I debug.print - nothing prints out. Could someone points out my error or how I go about setting global variables that I could reuse in different procedures within the same excel workbook. Thank you!

Code:
Public Sub Initiate()


Set sht_Paste = ThisWorkbook.Worksheets("Paste")
Set sht_2_Wks_Trades = ThisWorkbook.Worksheets("2_Wks_Trades")

Dim finalRow_Paste As Integer
Dim finalRow_2Wks_Trades As Integer

finalRow_Paste = sht_Paste.Cells(sht_Paste.Rows.Count, "a").End(xlUp).Row
finalRow_2_Wks_Trades = sht_2_Wks_Trades.Cells(sht_2_Wks_Trades.Rows.Count, "a").End(xlUp).Row


End Sub




Public Sub test()

    Call Initiate

    Debug.Print finalRow_Paste
    Debug.Print finalRow_2_Wks_Trades

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
these 2 lines need to be declared outside the sub but in the same module
Dim finalRow_Paste As Integer
Dim finalRow_2Wks_Trades As Integer

variables are not shared between subs unless they are declared at the top of the module
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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