Bonjour,
Je déclare des variables en "public" dans un UserForm que j'appelle dans un module.
Toutes les macros concernées sont indiquées en "Public sub".
Je ne comprend pas pourquoi les variables ne sont pas retrouvées. A chaque fois je suis obligé d'aligner tout le code à la suite pour que cela fonctionne.
Si vous voulez tester, je joins un document test.
Les codes dont il est question sont les suivants :
Dans l'US : "DashBoard"
Déclaration de nm et prn en public
Option Explicit
Public an As String, pst As String, nm As String, prn As String, Num As String, _
nv As String, tv As String, imma As String, nbpl As String
Public Sub Valid_dashboard_click()
Dim a As Integer
a = 0
If Me.ToggleButton1 = True Then
If Me.Nom <> "NOM" And Me.Prenom <> "Prenom" And Me.Nom <> "" And Me.Prenom <> "" And Me.Poste <> "Poste" Then
On Error Resume Next
If IsError(Sheets(nm & "_" & prn)) Then
Sheets.Add.Name = nm & "_" & prn
Else
MsgBox "Nom " & nm & "_" & prn & " déjà attribué, opération arrêtée"
Exit Sub
End If
Else
If Me.Nom = "NOM" Or Me.Nom = "" Then Me.Nom.BackColor = RGB(253, 253, 115): a = a + 1
If Me.Prenom = "Prenom" Or Me.Prenom = "" Then Me.Prenom.BackColor = RGB(253, 253, 115): a = a + 1
If Me.Poste = "Poste" Then Me.Poste.BackColor = RGB(253, 253, 115): a = a + 1
If a > 0 Then MsgBox "Veuillez renseigner les champs surlignés": Exit Sub
End If
Else: MsgBox "Aucune option n'a été sélectionnée": Exit Sub
End If
Call horaires
Call style_horaires
End Sub
Le second code se trouve dans le module "module_hor_plng" où les variables "nm" et "prn" sont "nulles" :
Public Sub horaires()
Dim a As Integer, lrpl As Long
With Sheets(nm & "_" & prn)
For a = 2 To 24
.Cells(a, 1) = a - 1
Next a
lrpl = .Cells(.Rows.Count, 1).End(xlUp).Row
'Insérer le nombre de lignes adéquat
For a = lrpl To 2 Step -1
If .Cells(a, 1) <> "" Then
.Cells(a, 1).Resize(3, 1).EntireRow.Insert
End If
Next a
lrpl = .Cells(.Rows.Count, 1).End(xlUp).Row
For a = lrpl To 2 Step -1
If .Cells(a + 1, 2) = "" Then .Cells(a, 2) = "45"
If .Cells(a + 1, 2) = "45" Then .Cells(a, 2) = "30"
If .Cells(a + 1, 2) = "30" Then .Cells(a, 2) = "15"
If .Cells(a + 1, 2) = "15" Then .Cells(a, 2) = "00"
If .Cells(a + 1, 2) = "0" Then .Cells(a, 2) = "45"
Next a
End With
Je vous remercie de votre attention,
Bonne soirée,
A plus tard !