public variables not working

jordanburch

Active Member
Joined
Jun 10, 2016
Messages
439
Office Version
  1. 2016
Hi All

This public variables isnt working


Public data_wbk1 As String
Public data_wbk2 As String
Public data_wbk3 As String
Public data_wbk4 As String
Public data_wbk5 As String
Public data_wbk6 As String
Public data_wbk7 As String
Public data_wbk8 As String
Public data_wbk9 As String
Public Sub openfiles()

data_wbk1 = InputBox("Enter FY I.E. FY20", Default:="FY20")
data_wbk2 = InputBox("Enter month I.E. 08-MAY20", Default:="08-MAY20")
data_wbk3 = InputBox("Enter monthFY I.E. MAY20:", Default:="MAY20")
Workbooks.Open ("K:\SHARED\TRANSFER\Enterprise Wide Suspense Initiative\Monthly Suspense Recon\" & data_wbk1 & "\" & data_wbk2 & "\" & "CARS" & "\" & data_wbk3 & " " & "CARS Detail Transaction Lines.xls*")
data_wbk4 = InputBox("Enter FY I.E. FY20", Default:="FY20")
data_wbk5 = InputBox("Enter month I.E. 08 - MAY20", Default:="08 - MAY 2020")
data_wbk6 = InputBox("Enter month Name I.E. YYYYMM:", Default:="202005")
data_wbk7 = InputBox("Enter month Name I.E. MAY:", Default:="MAY")
data_wbk8 = InputBox("Enter Prior month Name I.E. APRIL:", Default:="APRIL")
data_wbk9 = InputBox("Enter Prior month I.E. 07 - APR 2020", Default:="07 - APR 2020")

its not carrying to other subs in the same module. Whats wrong with it?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
When refering to those variables, you need to mention the module

VBA Code:
MsgBox ThisWorkbook.data_wbk2
If you put the declarations in a normal module, you won't need the ThisWorkbook qualification.
 
Upvote 0
so i have this

Set DSheet = Worksheets(data_wbk3 & data_wbk4 & "CARS")

it should be this

Set DSheet = Worksheets(thisworkbook.data_wbk3 & thisworkbook.data_wbk4 & "CARS")

?
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,136
Members
448,551
Latest member
Sienna de Souza

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