1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| Option Explicit
Dim CC() As Classe1
'---------------------------------------------------------------------------------------
' Purpose : Permet de boucler les Checkbox et de les instancier à l'aide du tableau CC
' de type Classe1
'---------------------------------------------------------------------------------------
'
Sub Initialize()
Dim CB As OLEObject
Dim i As Integer
For Each CB In ThisWorkbook.Worksheets("m_a").OLEObjects
If Left(CB.Name, 3) = "Chk" Then
i = i + 1
ReDim Preserve CC(1 To i)
Set CC(i) = New Classe1
Set CC(i).Chk = CB.Object
End If
Next CB
End Sub
'---------------------------------------------------------------------------------------
' Purpose : Procédure qui permet d'inscrire ou d'effacerle nom de l'appareil APP
' en fonction de sa valeur ETAT
' Le paramètre optionnel OCK (si à True) permet d'ajouter l'appareil APP
' à effacer de la colonne G dans la colonne L
' Si OCK est False ou omis, l'effacement de l'apperil ne s'accompagne
' pas des des inscriptions en colonne L
'---------------------------------------------------------------------------------------
'
Sub TestOnOff(ByVal App As String, ByVal Etat As Boolean, Optional OCK As Boolean)
Dim LastLigD As Long, LastLigB As Long, i As Long, j As Long
Dim Ws As Worksheet
Dim Tb, Td
With ThisWorkbook.Worksheets("APP")
LastLigD = .Cells(.Rows.Count, "A").End(xlUp).Row
Td = .Range("A2:F" & LastLigD)
End With
If OCK Then
Set Ws = ThisWorkbook.Worksheets("BD1")
Else
Set Ws = ThisWorkbook.Worksheets("BD")
End If
With Ws
LastLigB = .Cells(.Rows.Count, "B").End(xlUp).Row
Tb = .Range("B2:L" & LastLigB)
For i = 1 To LastLigD - 1
For j = 1 To LastLigB - 1
If Td(i, 6) = App And Td(i, 1) & "|" & Td(i, 2) & "|" & Td(i, 3) & "|" & Int(Td(i, 4)) = _
Tb(j, 1) & "|" & Tb(j, 2) & "|" & Tb(j, 3) & "|" & Int(Tb(j, 4)) Then
If Etat Then
If InStr(Tb(j, 6), App) = 0 Then Tb(j, 6) = Trim(Tb(j, 6) & " " & App)
If OCK Then Tb(j, 11) = Trim(Replace(Tb(j, 11), App, ""))
Else
Tb(j, 6) = Trim(Replace(Tb(j, 6), App, ""))
If OCK Then
If InStr(Tb(j, 11), App) = 0 Then Tb(j, 11) = Trim(Tb(j, 11) & " " & App)
End If
End If
End If
Next j
Next i
.Range("B2:L" & LastLigB) = Tb
End With
Set Ws = Nothing
End Sub
Sub MAJ()
Dim i As Integer
Dim App As String
Dim Etat As Boolean
Application.ScreenUpdating = False
Initialize
For i = 1 To UBound(CC)
App = CC(i).Chk.Caption
Etat = CC(i).Chk.Value
TestOnOff App, Etat, True
Next i
End Sub |