Remplacer une valeur à partir d'une cellule adjacente

Bonjour à tous,

Je souhaiterais remplacer la valeur de la colonne H si la valeur de la colonne A contient "-2" , "-3", "-4", "-5", "-6" ou "-7".

Cette règle devrait s'exécuter à partir de la ligne 7, le document n'aura pas toujours le même nombre de ligne.

Merci pour votre aide.

13 réponses

  1. Ouf !!!!
    Pas tout lu mais, essaies déjà ceci
    1. supprimes cete ligne
    Option Explicit
    2. mets ces trois lignes dans la procedure OK
    Const cotest = "A"
    Const coremp = "I"
    Const lideb = 7
    comme ceci
    Public Sub OK
    Const cotest = "A"
    Const coremp = "I"
    Const lideb = 7
    Dim .....
    etc ...
    End Sub ' de OK

    Bon courage
    0
    1. CCm81,

      J'ai essayé de l'insérer dans ma Macro (qui exécute de la mise en page et récupère des données d'une autre feuille Excel).

      Voici Mon Code : (à l'exécution : Erreur de compilation)

      Attention aux Yeux !!

      Sub PlanningCOLLAGE()
      '

      ' Ordre des feuilles/ ordre des colleuses

      Windows("Planning Collage.XLS").Activate

      Sheets("BOBST ALPINA 75").Select
      Sheets("BOBST ALPINA 75").Move Before:=Sheets(1)
      Sheets("BOBST EXPERFOLD 80").Select
      Sheets("BOBST EXPERFOLD 80").Move Before:=Sheets(2)
      Sheets("BOBST MEDIA 45 VERSION 2").Select
      Sheets("BOBST MEDIA 45 VERSION 2").Move Before:=Sheets(3)
      Sheets("BOBST MEDIA 45").Select
      Sheets("BOBST MEDIA 45").Move Before:=Sheets(3)

      Call OK

      Call PlanningCOLLAGE2

      End Sub

      Option Explicit

      Const cotest = "A"
      Const coremp = "I"
      Const lideb = 7

      Public Sub OK()

      ' supprime la valeur "Caisses" en double (Appels)

      Dim li As Long, lifin As Long, s As String, rt As Long, dc As Long
      Application.ScreenUpdating = False
      lifin = Range(cotest & Rows.Count).End(xlUp).Row
      For li = lideb To lifin
      s = Range(cotest & li).Value
      rt = InStr(1, s, "-")
      If rt > 0 Then
      dc = Right(s, 1)
      If dc >= 2 And dc <= 7 Then
      Range(coremp & li).NumberFormat = "General"
      Range(coremp & li).Formula = "=NA()"
      End If
      End If
      Next li
      Application.ScreenUpdating = True
      End Sub

      Sub PlanningCOLLAGE2()

      'Mise en Page

      Sheets("BOBST ALPINA 75").Activate
      With Selection
      .HorizontalAlignment = xlGeneral
      .VerticalAlignment = xlCenter
      .WrapText = False
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = True
      End With
      Selection.UnMerge
      Range("A2:L2").Select
      Selection.ClearContents
      Range("A3:L3").Select
      With Selection
      .HorizontalAlignment = xlGeneral
      .VerticalAlignment = xlCenter
      .WrapText = False
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = True
      End With
      Selection.UnMerge
      Range("A4").Select

      Range("J5:K5").Select
      With Selection
      .HorizontalAlignment = xlGeneral
      .VerticalAlignment = xlCenter
      .WrapText = True
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = True
      End With
      Selection.UnMerge

      Columns("J:J").Select
      Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

      Range("J5:J6").Select
      With Selection
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlCenter
      .WrapText = True
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
      End With
      Selection.Merge
      ActiveCell.FormulaR1C1 = "Objectif Vitesse"
      Range("K5:L5").Select
      With Selection
      .HorizontalAlignment = xlCenter
      .VerticalAlignment = xlCenter
      .WrapText = True
      .Orientation = 0
      .AddIndent = False
      .IndentLevel = 0
      .ShrinkToFit = False
      .ReadingOrder = xlContext
      .MergeCells = False
      End With
      Selection.Merge
      Range("A5:A6").Select
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ThemeColor = xlThemeColorLight1
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      Selection.Font.Bold = True
      Range("B5:B6").Select
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ThemeColor = xlThemeColorLight1
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      Selection.Font.Bold = True
      Range("C5:C6").Select
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ThemeColor = xlThemeColorLight1
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      Selection.Font.Bold = True
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      Range("D5:D6").Select
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      Selection.Font.Bold = True
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      Range("E5:E6").Select
      ActiveCell.FormulaR1C1 = "Quantité"
      Range("E5:E6").Select
      Selection.Font.Bold = True
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      Range("F5:F6").Select
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      Selection.Font.Bold = True
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      Range("G5:G6").Select
      Selection.Font.Bold = True
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      Range("H5:H6").Select
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ThemeColor = xlThemeColorLight1
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      Selection.Font.Bold = True
      Range("I5:I6").Select
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      With Selection.Font
      .Name = "Calibri"
      .Size = 12
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ThemeColor = xlThemeColorLight1
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      Selection.Font.Bold = True
      Range("J5:J6").Select
      Selection.Font.Bold = True
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      Range("K5:L5").Select
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      Selection.Font.Bold = True
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      Range("K6").Select
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      Selection.Font.Bold = True
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ThemeColor = xlThemeColorLight1
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      Range("L6").Select
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .ThemeColor = xlThemeColorLight1
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With
      Selection.Font.Bold = True
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      Range("M5:M6").Select
      With Selection.Interior
      .Pattern = xlSolid
      .PatternColorIndex = xlAutomatic
      .ThemeColor = xlThemeColorDark1
      .TintAndShade = -0.349986266670736
      .PatternTintAndShade = 0
      End With
      Selection.Font.Bold = True
      With Selection.Font
      .Name = "Calibri"
      .Size = 16
      .Strikethrough = False
      .Superscript = False
      .Subscript = False
      .OutlineFont = False
      .Shadow = False
      .Underline = xlUnderlineStyleNone
      .TintAndShade = 0
      .ThemeFont = xlThemeFontMinor
      End With

      Columns("B:B").ColumnWidth = 42.57
      Columns("C:C").ColumnWidth = 36.43
      Columns("D:D").ColumnWidth = 20.57
      Columns("E:E").ColumnWidth = 11.86
      Columns("J:J").ColumnWidth = 14.86
      Columns("L:L").ColumnWidth = 6.43
      Range("A1").Select

      End Sub
      0
      1. Pour plus de clarté , il existe des balises que tu peux utiliser pour inscrire ton code :

        Rajoute < code basic> avant et < /code> après. sans les 2 espaces avec le "<"

        Cordialement,
        0
    2. Pourquoi veux tu l'intégrer à une macro existante.
      Tu peux simplement faire un appel à elle dans ta macro :
      Sub ta_macro()
      ....

      Call OK
      ...
      End Sub

      N'oublies pas les constantes en début de code qui dépendent de ta configuration (colonnes concernées et premiere ligne à traiter)
      0
      1. Merci ccm81 ce code fonctionne comme je le souhaite,

        Je rencontre des difficulté pour exécuter l'ensemble de mes commandes.

        Comment intégrer ce code sur une macro existante ?

        Merci pour ton aide
        0
        1. Avec une macro
          http://www.cjoint.com/c/FIDjShdktoq

          Cdlmnt
          0
          1. Merci Albkan, mais cela ne semble pas être la solution.

            Est il possible d'intégrer cette formule dans une Macro.
            0
            1. Par un colisage (ce tableau est extrait d'une application)

              Le nombre a peu d'importance pour le sujet.
              0
              1.  
                Bonjour bambooetugo et Fahora,

                Peut-être que cette formule (à adapter) pourra aller :
                =SI(LIGNE()<7;"";SI(ET(A1>=-7;A1<=-2);NA();I1))

                Formule à mettre en B1 (par exemple), et à tirer vers le bas.

                Cordialement.  😊

                PS : Désolé, pas le temps de voir le fichier joint !
                 
                0
            2. Dsl je parlais de la colonne I et non de la H

              Je souhaite simplement que pour chaque ligne de la colonne A avec indice supplémentaire (-2,-3....) il remplace la valeur de la colonne I par "NA".

              Merci
              0
              1. Même question :) . Comment sont déterminés les valeurs de ta colonne I ? (Nbr de caisses)
                0
            3. Bonjour Fahora,

              La valeur de la colonne H dépends de l'information de la colonne A:
              (colonne A contient "-2" , "-3", "-4", "-5", "-6" ou "-7".)

              En effet je souhaite passer par une Macro.

              Merci pour votre aide
              0
              1. Avec tout le respect que je te dois , tu ne réponds pas à ma question. Actuellement, dans ta colonne H , il y a CU10/CU12 ou CU38, comment sont déterminés ces valeurs ?
                0
            4. Bonjour ,

              comment détermines-tu la valeur de la colonne H ?

              Important, si cette valeur est détermine aléatoirement (c à d s'il n'y a pas de logique dans cette valeur), il faudra certainement passer par VBA ou faire une formule pour chaque ligne

              Cordialement,

              Nos seules limites sont celles que nous nous imposons nous-même.
              La politesse et un merci ne tuent pas. Il existe un bouton pour "Résolu" pour confirmer que     votre problème n'en est plus un. Fahora
              0
              1. Merci pour vos réponses.

                Quelques précisions :

                1 - Je veux remplacer la valeur de la colonne H par NA. (Soit dans l'exemple sur les lignes 8-14 et 15
                2 - A partir de la ligne 7, le nombre de ligne est variable

                https://www.cjoint.com/c/FIDgmJjjJsn

                Merci pour votre aide.
                0
                1. Bonjour bambooetugo et ccm81,

                  Il manque un renseignement important !

                  De la ligne 7 à la dernière ligne n, si la valeur de la colonne A
                  est entre -2 et -7 inclus : remplacer la valeur de la colonne H
                  par quoi ?

                  Cordialement.  😊
                   
                  0
                  1. Bonjour

                    Peux tu envoyer un bout de ton fichier, sur cjoint.com et joindre le lien obtenu à ton prochain message. N'oublies pas d'y ajouter des explications et des exemples de résultat attendu

                    1) Tu vas dans https://www.cjoint.com/
                    2) Tu cliques sur [Parcourir] pour sélectionner ton fichier
                    3) Tu descends en bas de la page pour cliquer sur [Créer le lien Cjoint]
                    4) Au bout de quelques secondes la deuxième page s'affiche, avec le lien
                    en bleu souligné ; tu le sélectionnes et tu fais "Copier"
                    5) Tu reviens dans ta discussion sur CCM, et dans ton message de réponse
                    tu fais "Coller".

                    Cdlmnt
                    0