I am learning how to use public variables in my excel projects, at this moment I am running into the following problem: I am declaring my variable in a single module as follows:
Option Explicit
Public Pass_H As String
Public Pass_L As String
At the beginning of the project I declare as follows:
Private Sub Workbook_Open()
ThisWorkbook.Windows(1).Visible = False
Pass_H = Sheets("Pass").Range("C4").Value
Pass_L = Sheets("Pass").Range("F4").Value
And I use it in other projects of other sheets for example:
Private Sub CB_3_Click()
Dim Final_T As Range, Final_N As Range
With ActiveSheet
Set Final_T = .Range("A1").End(xlToRight)
Set Final_N = Final_T.End(xlDown)
.Unprotect Pass_H
.Range("A1", Final_N).Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes
.Protect (Pass_H)
End With
End Sub
Or:
Private Sub Blo()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
ws.Protect (Pass_H)
Next ws
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
But even in these simple lines the value is lost at some point and it appears as nothing. I already went through the rest of the project and the only statement or reference is in the Workbook.Open() I don't understand what I could be doing wrong.