I'm trying to use global variables in a excel macro I'm creating, but i can't get them to work. I wrote te following code:
Public globalVar As Integer
Public Sub TestGlobal()
SetGlobalVar
GetGlobalVar
End Sub
Public Sub SetGlobalVar()
globalVar = 5
End Sub
Public Sub GetGlobalVar()
Debug.Print "globalVar = "
Debug.Print globalVar
End Sub
I expected this code to show globalVar = 5, but it's showing globalVar =, and when I put the mouse over the globalVar variable in SetGlobalVar it shows "5", but when I do that on GetGlobalVar, it shows "Empty".
What am I doing wrong? Shouldn't the value be the same, since the variable is global?

globalVar =then5on the next line as expected. Right click globalVar in the declaration line and add watch then you can debug line by line and see how its value is changing.Debug.Print "globalVar = " & globalVar?