Diminuer la longueur d'une macro

Résolu
JCB40 Messages postés 2878 Date d'inscription lundi 2 juillet 2018 Statut Membre Dernière intervention 20 avril 2024 - Modifié le 30 nov. 2023 à 16:40
yg_be Messages postés 22733 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 29 avril 2024 - 1 déc. 2023 à 21:46

Bonjour,

Vous serait il possible de me simplifier cette macro que j'ai créé,mais je ne sais pas la simplifier

Je vous remercie par avance

Sub test()
' test Macro
   If Sheets("Liens").Range("A10") = "A" Then
    Sheets("Résultat").Select
    Range("F1").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
      Else
   If Sheets("Liens").Range("A10") = "B" Then
    Sheets("Résultat").Select
    Range("G3").Select
   With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Else
    If Sheets("Liens").Range("A10") = "C" Then
    Sheets("Résultat").Select
    Range("H5").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    End If
    End If
    End If
End Sub


Windows / Firefox 120.0


A voir également:

2 réponses

f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 702
30 nov. 2023 à 16:57

Bonjour,

Sub test()
    ' test Macro
    Cel = ""
    A10 = Sheets("Liens").Range("A10")
    If A10 <> "" Then
        If A10 = "A" Then
             Cel = "F1"
         ElseIf A10 = "B" Then
             Cel = "G3"
         ElseIf A10 = "C" Then
             Cel = "H5"
         End If
         With Worksheets("Résultat").Range(Cel).Interior
             .Pattern = xlSolid
             .PatternColorIndex = xlAutomatic
             .Color = 255
             .TintAndShade = 0
             .PatternTintAndShade = 0
         End With
    End If
End Sub
1
yg_be Messages postés 22733 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 29 avril 2024 1 477
30 nov. 2023 à 17:18

bonjour,

je pense utile de vérifier que A10 contient une des valeurs cherchées:

Sub test()
    ' test Macro
    Cel = ""
    A10 = Sheets("Liens").Range("A10")
        If A10 = "A" Then
             Cel = "F1"
         ElseIf A10 = "B" Then
             Cel = "G3"
         ElseIf A10 = "C" Then
             Cel = "H5"
         End If
         If cel <> "" Then
            With Worksheets("Résultat").Range(Cel).Interior
             .Pattern = xlSolid
             .PatternColorIndex = xlAutomatic
             .Color = 255
             .TintAndShade = 0
             .PatternTintAndShade = 0
            End With
         End If
End Sub
1
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 702 > yg_be Messages postés 22733 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 29 avril 2024
1 déc. 2023 à 07:43

Bonjour,

Ben, qu'est ce que j'ai ecrit en ligne 5!

0
yg_be Messages postés 22733 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 29 avril 2024 1 477 > f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024
1 déc. 2023 à 12:50

Si A10 contient "D", que va faire la macro?

0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 702 > yg_be Messages postés 22733 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 29 avril 2024
1 déc. 2023 à 16:49

Re,

A lui de voir...

0
yg_be Messages postés 22733 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 29 avril 2024 1 477 > f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024
1 déc. 2023 à 21:46

Si je lis le code, la macro va se planter.

0
JCB40 Messages postés 2878 Date d'inscription lundi 2 juillet 2018 Statut Membre Dernière intervention 20 avril 2024 461
1 déc. 2023 à 10:01

Bonjour

Merci pour vos réponses cela correspond à mes besoins

Crdlt


0