Diminuer la longueur d'une macro

Résolu
JCB40 Messages postés 3013 Date d'inscription   Statut Membre Dernière intervention   -  
yg_be Messages postés 23541 Date d'inscription   Statut Contributeur Dernière intervention   -

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 17277 Date d'inscription   Statut Membre Dernière intervention   1 713
 

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 23541 Date d'inscription   Statut Contributeur Dernière intervention   1 584
 

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 17277 Date d'inscription   Statut Membre Dernière intervention   1 713 > yg_be Messages postés 23541 Date d'inscription   Statut Contributeur Dernière intervention  
 

Bonjour,

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

0
yg_be Messages postés 23541 Date d'inscription   Statut Contributeur Dernière intervention   1 584 > f894009 Messages postés 17277 Date d'inscription   Statut Membre Dernière intervention  
 

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

0
f894009 Messages postés 17277 Date d'inscription   Statut Membre Dernière intervention   1 713 > yg_be Messages postés 23541 Date d'inscription   Statut Contributeur Dernière intervention  
 

Re,

A lui de voir...

0
yg_be Messages postés 23541 Date d'inscription   Statut Contributeur Dernière intervention   1 584 > f894009 Messages postés 17277 Date d'inscription   Statut Membre Dernière intervention  
 

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

0
JCB40 Messages postés 3013 Date d'inscription   Statut Membre Dernière intervention   463
 

Bonjour

Merci pour vos réponses cela correspond à mes besoins

Crdlt


0