How do I assign string variable values across multiple subs and modules once?

Gregory72

New Member
Joined
Jun 25, 2014
Messages
12
Scenario:
I have 3 subs inModule 1.
Each one of thesesubs uses some but not all of 5 available variables. All Strings.

Instead of pickingand choosing which variables to define in each of the 3 subs, I'd like tocreate 1 more sub in Module 2. This sub would be called at the start of each ofthe 3 subs in Module 1 with the intent of defining all variables all the time.

Currently, it showsthat the the variable was defined, but it doesn't always translate into each ofmy other subs. I have message boxes in both the sub in Module 2 and the sub inModule 1 to show the variable's value during the run. Whenever the message boxin Module 1 runs, it doesn't always give me a value and is sometime blank.

Does anyone know whymy variables won't always translate from sub4 in Module 2 to a subs1-3 inModule 1 after sub4 is called? What's weird is that it started out NOT workingfor me, and then it started working, so I added more variables, and now it'sNOT working again for those added variable. It's like there's a time limit onwhen you add it or something, which doesn't make any sense to me.

If there's a betterway to do this, please let me know!

Rich (BB code):
Rich (BB code):
'In Module 1
Public Sub one()
Call four
MsgBox (variable1)
MsgBox (variable2)
End Sub
 
Public Sub two()
Call Variables
MsgBox (variable1)
MsgBox (variable4)
End Sub
 
Public Sub three()
Call Variables
MsgBox (variable3)
MsgBox (variable5)
End Sub
 
 
'In Module 2

Public variable1 As String
Public variable2 As String
Public variable3 As String
Public variable4 As String
Public variable5 As String


PublicSub four()
WithActiveWorkbook
   'selects column C first
   CurrRow = ActiveCell.Row
   Range("C" & CurrRow).Select
   variable1 = ActiveCell.Offset(0, -1).Value
   variable2 = ActiveCell.Value
   variable3 = ActiveCell.Offset(0, 1).Value
   variable4 = ActiveCell.Offset(0, 2).Value
   variable5 = ActiveCell.Offset(0, 3).Value
EndWith
EndSub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,216,119
Messages
6,128,941
Members
449,480
Latest member
yesitisasport

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