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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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