Skip to content

Instantly share code, notes, and snippets.

@erajanraja24
Last active June 21, 2016 16:21
Show Gist options
  • Save erajanraja24/3ee5a447d866b096f8161fb4597e76d2 to your computer and use it in GitHub Desktop.
Save erajanraja24/3ee5a447d866b096f8161fb4597e76d2 to your computer and use it in GitHub Desktop.
Excel VBA Scope of variables
'In Module 1
Option Private Module
Public var1 As Integer
Sub Public_Scope_1()
var1 = 20
Debug.Print "Value of var1 in Public_Scope_1: "; var1
var1 = var1 + 15
End Sub
'Go to Developer tab, insert a Module by Insert->Module and copy paste the above code in the Module1
'In Module 2
Sub Public_Scope_2()
Debug.Print "Value of var1 in Public_Scope_2: "; var1
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment