OVH Cloud OVH Cloud

Lisibilité de procédure 2 en 1

4 réponses
Avatar
Golf
Bonsoir
J'ai créé cette procédure ouf... Mais je pense que je pourrais l'alléger
afin de la rendre plus lisible. En fait, j'ai dû la séparer en deux, car
avec les And et Or, je me mélange les pinceaux.
Pouvez-vous m'aider, afin de n'en faire qu'une ?

Sub records()
' le test
If frm_table.Lbl_type.Caption = "L'addition" And _
Sheets("Params").[I2] = "20" And _
Sheets("Params").[F3] = "" Then
Sheets("Params").Unprotect Password:="toto"
Sheets("Params").[F3] = Sheets("Params").[I1]
'frm_table.Lbl_félicitations.Visible = True
frm_noms_records.Show
Sheets("Params").Protect Password:="toto"
End If

If frm_table.Lbl_type.Caption = "L'addition" And _
Sheets("Params").[I2] = "20" And _
Sheets("Params").[F3] > Sheets("Params").[I1] Then
Sheets("Params").Unprotect Password:="toto"
Sheets("Params").[F3] = Sheets("Params").[I1]
'frm_table.Lbl_félicitations.Visible = True
frm_noms_records.Show
Sheets("Params").Protect Password:="toto"
End If

End Sub

4 réponses

Avatar
LeSteph
Bonsoir,

Pour reprendre simplement ton code et non testé

Sub records()
Dim montest as string
With Worksheets("Params")
montest=frm_table.Lbl_type.Caption & .[i2]
If montest="L'addition20" Then
if .[F3] > .[i1] or .[F3]="" Then
.unprotect password:="toto"
.[F3] = .[I1]
'frm_table.Lbl_félicitations.Visible = True
frm_noms_records.Show
.Protect Password:="toto"
End if
End if
End with
End Sub

LeSteph
"Golf" a écrit dans le message de
news:
Bonsoir
J'ai créé cette procédure ouf... Mais je pense que je pourrais l'alléger
afin de la rendre plus lisible. En fait, j'ai dû la séparer en deux, car
avec les And et Or, je me mélange les pinceaux.
Pouvez-vous m'aider, afin de n'en faire qu'une ?

Sub records()
' le test
If frm_table.Lbl_type.Caption = "L'addition" And _
Sheets("Params").[I2] = "20" And _
Sheets("Params").[F3] = "" Then
Sheets("Params").Unprotect Password:="toto"
Sheets("Params").[F3] = Sheets("Params").[I1]
'frm_table.Lbl_félicitations.Visible = True
frm_noms_records.Show
Sheets("Params").Protect Password:="toto"
End If

If frm_table.Lbl_type.Caption = "L'addition" And _
Sheets("Params").[I2] = "20" And _
Sheets("Params").[F3] > Sheets("Params").[I1] Then
Sheets("Params").Unprotect Password:="toto"
Sheets("Params").[F3] = Sheets("Params").[I1]
'frm_table.Lbl_félicitations.Visible = True
frm_noms_records.Show
Sheets("Params").Protect Password:="toto"
End If

End Sub




Avatar
michdenis
Bonjour Golf,

Concernant les opérations de "Protect" et "UnProtect" dans tes macros, tu devrais utiliser ceci dans le ThisWorkbook de
ton classeur... tu n'aurais plus besoin de te préoccuper de l'élément "Protection" lors de l'éxécution de Macro dans la
feuille spécifiée. Cette procédure s'exécute à chaque ouverture de ton classeur. Adapte le nom de la feuille selon celle
de ton application.
'-----------------------
Private Sub Workbook_Open()

With Worksheets("Feuil1")
.Protect "toto", True, True, True, True
End With

End Sub
'-----------------------


ET ta procédure pourrait donner quelque chose comme ceci :

'------------------------------
Sub Test() 'pas tester

Dim Sh As Worksheet, Lbl As MSForms.Label
Set Sh = Sheets("Params")
Set Lbl = frm_table.Lbl_type

With Lbl
If .Caption = "L'addition" Then
With Sh
If .[I2] = "20" Then
Select Case .[F3]
Case Is = "", Is > .[I1]
.[F3] = .[I1]
frm_noms_records.Show
End Select
End If
End With
End If
End With
Set Sh = Nothing: Set Lbl = Nothing

End Sub
'------------------------------


Salutations!




"Golf" a écrit dans le message de news:
Bonsoir
J'ai créé cette procédure ouf... Mais je pense que je pourrais l'alléger
afin de la rendre plus lisible. En fait, j'ai dû la séparer en deux, car
avec les And et Or, je me mélange les pinceaux.
Pouvez-vous m'aider, afin de n'en faire qu'une ?

Sub records()
' le test
If frm_table.Lbl_type.Caption = "L'addition" And _
Sheets("Params").[I2] = "20" And _
Sheets("Params").[F3] = "" Then
Sheets("Params").Unprotect Password:="toto"
Sheets("Params").[F3] = Sheets("Params").[I1]
'frm_table.Lbl_félicitations.Visible = True
frm_noms_records.Show
Sheets("Params").Protect Password:="toto"
End If

If frm_table.Lbl_type.Caption = "L'addition" And _
Sheets("Params").[I2] = "20" And _
Sheets("Params").[F3] > Sheets("Params").[I1] Then
Sheets("Params").Unprotect Password:="toto"
Sheets("Params").[F3] = Sheets("Params").[I1]
'frm_table.Lbl_félicitations.Visible = True
frm_noms_records.Show
Sheets("Params").Protect Password:="toto"
End If

End Sub
Avatar
golf
Merci beaucoup Denis
Golf


-----Message d'origine-----
Bonjour Golf,

Concernant les opérations de "Protect" et "UnProtect"
dans tes macros, tu devrais utiliser ceci dans le

ThisWorkbook de
ton classeur... tu n'aurais plus besoin de te préoccuper
de l'élément "Protection" lors de l'éxécution de Macro

dans la
feuille spécifiée. Cette procédure s'exécute à chaque
ouverture de ton classeur. Adapte le nom de la feuille

selon celle
de ton application.
'-----------------------
Private Sub Workbook_Open()

With Worksheets("Feuil1")
.Protect "toto", True, True, True, True
End With

End Sub
'-----------------------


ET ta procédure pourrait donner quelque chose comme ceci :

'------------------------------
Sub Test() 'pas tester

Dim Sh As Worksheet, Lbl As MSForms.Label
Set Sh = Sheets("Params")
Set Lbl = frm_table.Lbl_type

With Lbl
If .Caption = "L'addition" Then
With Sh
If .[I2] = "20" Then
Select Case .[F3]
Case Is = "", Is > .[I1]
.[F3] = .[I1]
frm_noms_records.Show
End Select
End If
End With
End If
End With
Set Sh = Nothing: Set Lbl = Nothing

End Sub
'------------------------------


Salutations!




"Golf" a écrit dans le message de
news:

Bonsoir
J'ai créé cette procédure ouf... Mais je pense que je
pourrais l'alléger

afin de la rendre plus lisible. En fait, j'ai dû la
séparer en deux, car

avec les And et Or, je me mélange les pinceaux.
Pouvez-vous m'aider, afin de n'en faire qu'une ?

Sub records()
' le test
If frm_table.Lbl_type.Caption = "L'addition" And _
Sheets("Params").[I2] = "20" And _
Sheets("Params").[F3] = "" Then
Sheets("Params").Unprotect Password:="toto"
Sheets("Params").[F3] = Sheets("Params").[I1]
'frm_table.Lbl_félicitations.Visible = True
frm_noms_records.Show
Sheets("Params").Protect Password:="toto"
End If

If frm_table.Lbl_type.Caption = "L'addition" And _
Sheets("Params").[I2] = "20" And _
Sheets("Params").[F3] > Sheets("Params").[I1] Then
Sheets("Params").Unprotect Password:="toto"
Sheets("Params").[F3] = Sheets("Params").[I1]
'frm_table.Lbl_félicitations.Visible = True
frm_noms_records.Show
Sheets("Params").Protect Password:="toto"
End If

End Sub



.



Avatar
golf
Merci beaucoup Lesteph
Golf

-----Message d'origine-----
Bonsoir,

Pour reprendre simplement ton code et non testé

Sub records()
Dim montest as string
With Worksheets("Params")
montest=frm_table.Lbl_type.Caption & .[i2]
If montest="L'addition20" Then
if .[F3] > .[i1] or .[F3]="" Then
..unprotect password:="toto"
..[F3] = .[I1]
'frm_table.Lbl_félicitations.Visible = True
frm_noms_records.Show
..Protect Password:="toto"
End if
End if
End with
End Sub

LeSteph
"Golf" a écrit dans le message de
news:
Bonsoir
J'ai créé cette procédure ouf... Mais je pense que je
pourrais l'alléger


afin de la rendre plus lisible. En fait, j'ai dû la
séparer en deux, car


avec les And et Or, je me mélange les pinceaux.
Pouvez-vous m'aider, afin de n'en faire qu'une ?

Sub records()
' le test
If frm_table.Lbl_type.Caption = "L'addition" And _
Sheets("Params").[I2] = "20" And _
Sheets("Params").[F3] = "" Then
Sheets("Params").Unprotect Password:="toto"
Sheets("Params").[F3] = Sheets("Params").[I1]
'frm_table.Lbl_félicitations.Visible = True
frm_noms_records.Show
Sheets("Params").Protect Password:="toto"
End If

If frm_table.Lbl_type.Caption = "L'addition" And _
Sheets("Params").[I2] = "20" And _
Sheets("Params").[F3] > Sheets("Params").[I1] Then
Sheets("Params").Unprotect Password:="toto"
Sheets("Params").[F3] = Sheets("Params").[I1]
'frm_table.Lbl_félicitations.Visible = True
frm_noms_records.Show
Sheets("Params").Protect Password:="toto"
End If

End Sub





.