XL 2019 Formulaire Excel - TxtBox avec couleur de la celle associée

Lindsay_RBD

XLDnaute Nouveau
Bonjour à tous,

Je suis actuellement entrain de travailler sur un nouveau formulaire. Je vais essayer d'être la plus claire possible pour vous expliquer mon problème :

Lorsque je clique sur le bouton "Rechercher une référence", un formulaire s'ouvre. J'inscris mon numéro de lot et celui-ci m'indique différentes données donc le statut des lots associés (rouge, orange ouvert).
Une référence a 11 numéro lot. Chaque lot est associé à un TxtBox dans mon formulaire.

Malheureusement, je n'arrive pas à associer l'ensemble de mes numéros de lot, à la bonne couleur de mon tableau Excel.

Le formulaire "Rechercher un lot" fonctionne cependant parfaitement bien et associe bien la couleur.

Actuellement mon code ressemble à ceci, et je pense avoir un soucis au niveau du If/Then/Else :
VB:
Private Sub btn_rechercher_Click()
Dim sel As Range, col As Long

Sheets("Suivi des lots").Select

On Error Resume Next 'éviter une erreur si "co = sel column" ne trouve pas la colonne
        Set sel = Sheets("Suivi des lots").Range("C6:CZ6").Find(Me.RefMatiere.Value, , xlValues, xlWhole)
    col = sel.Column 'identifier la colonne correspondante au résultat de recherche
    
    If sel Is Nothing Then _
        NumLotMatiere1.BackColor = RGB(255, 0, 0)
        NumLotMatiere2.BackColor = RGB(255, 0, 0)
        NumLotMatiere3.BackColor = RGB(255, 0, 0)
        NumLotMatiere4.BackColor = RGB(255, 0, 0)
        NumLotMatiere5.BackColor = RGB(255, 0, 0)
        NumLotMatiere6.BackColor = RGB(255, 0, 0)
        NumLotMatiere7.BackColor = RGB(255, 0, 0)
        NumLotMatiere8.BackColor = RGB(255, 0, 0)
        NumLotMatiere9.BackColor = RGB(255, 0, 0)
        NumLotMatiere10.BackColor = RGB(255, 0, 0)
        NumLotMatiere11.BackColor = RGB(255, 0, 0)
        
    Else
        DesignMatiere = Cells(7, col).Value
        NumLotMatiere1 = Cells(9, col).Value
            With NumLotMatiere1
            .BackColor = IIf(sel.Interior.ColorIndex = 50, &HC000&, _
                             IIf(sel.Interior.ColorIndex = 45, &H80FF&, &HFF&))
           End With
    
        NumLotMatiere2 = Cells(10, col).Value
        With NumLotMatiere2
           .BackColor = IIf(sel.Interior.ColorIndex = 50, &HC000&, _
                             IIf(sel.Interior.ColorIndex = 45, &H80FF&, &HFF&))
        End With

        NumLotMatiere3 = Cells(11, col).Value
        With NumLotMatiere3
           .BackColor = IIf(sel.Interior.ColorIndex = 50, &HC000&, _
                             IIf(sel.Interior.ColorIndex = 45, &H80FF&, &HFF&))
            End With

        NumLotMatiere4 = Cells(12, col).Value
        With NumLotMatiere4
          .BackColor = IIf(sel.Interior.ColorIndex = 50, &HC000&, _
                             IIf(sel.Interior.ColorIndex = 45, &H80FF&, &HFF&))
            End With

        NumLotMatiere5 = Cells(13, col).Value
        With NumLotMatiere5
            .BackColor = IIf(sel.Interior.ColorIndex = 50, &HC000&, _
                             IIf(sel.Interior.ColorIndex = 45, &H80FF&, &HFF&))
            End With

        NumLotMatiere6 = Cells(14, col).Value
        With NumLotMatiere6
            .BackColor = IIf(sel.Interior.ColorIndex = 50, &HC000&, _
                             IIf(sel.Interior.ColorIndex = 45, &H80FF&, &HFF&))
            End With

        NumLotMatiere7 = Cells(15, col).Value
        With NumLotMatiere7
            .BackColor = IIf(sel.Interior.ColorIndex = 50, &HC000&, _
                             IIf(sel.Interior.ColorIndex = 45, &H80FF&, &HFF&))
            End With

        NumLotMatiere8 = Cells(16, col).Value
        With NumLotMatiere8
        .BackColor = IIf(sel.Interior.ColorIndex = 50, &HC000&, _
                             IIf(sel.Interior.ColorIndex = 45, &H80FF&, &HFF&))
            End With

        NumLotMatiere9 = Cells(17, col).Value
        With NumLotMatiere9
            .BackColor = IIf(sel.Interior.ColorIndex = 50, &HC000&, _
                             IIf(sel.Interior.ColorIndex = 45, &H80FF&, &HFF&))
            End With

        NumLotMatiere10 = Cells(18, col).Value
        With NumLotMatiere10
           .BackColor = IIf(sel.Interior.ColorIndex = 50, &HC000&, _
                             IIf(sel.Interior.ColorIndex = 45, &H80FF&, &HFF&))
            End With

        NumLotMatiere11 = Cells(19, col).Value
        With NumLotMatiere11
            .BackColor = IIf(sel.Interior.Color = 50, &H33CC33, _
                            IIf(sel.Interior.ColorIndex = 45, &H128AE4, &H808080))
            End With
    End If
          
End Sub

Je vous joins le fichier Excel.

Je vous remercie par avance pour votre aide ! :)
 

Pièces jointes

  • Fichier Excel.xlsm
    41.6 KB · Affichages: 2

Lindsay_RBD

XLDnaute Nouveau
Bonjour
Une version revue et qui ne plante plus.
Bonjour Yal :)

Merci pour ce premier retour. Malheureusement lorsque j'effectue la recherche par référence, les couleurs de correspondent pas au couleur des cellules associées comme tu peux le voir ci-dessous.
L'ensemble des TextBox apparaissent en rouge ou grise alors qu'il faudrait qu'elles reprennent la couleur des cellules du tableau associé
1664441078299.png
 

Discussions similaires

Réponses
8
Affichages
615

Statistiques des forums

Discussions
311 711
Messages
2 081 792
Membres
101 817
dernier inscrit
carvajal