Microsoft 365 Copier juste couleur cellule.

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Francky79

XLDnaute Occasionnel
Bonjour,

je recherche le moyen de copier juste la couleur de fond (la couleur résulte d'une MFC) d'une cellule sur une autre feuille en VBA mais sans la MFC.
Double clic dans une cellule, insertion de la date, copier couleur cellule, recherche de la ligne correspondante sur feuille base et copier la couleur.
Voir fichier en pièce jointe, le code est de ma conception avec ma connaissance en VBA qui n'est pas très grande 🙂

Merci pour votre aide
 

Pièces jointes

Solution
OK alors :
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("AD7:AD1000")) Is Nothing Then Exit Sub
Dim lig As Variant
Cancel = True
Target = Date
With Sheets("Base")
    lig = Application.Match(Cells(Target.Row, 1), .Columns("E"), 0)
    If IsNumeric(lig) Then .Range("Q" & lig).Interior.Color = Cells(Target.Row, "AR").DisplayFormat.Interior.Color
End With
End Sub
OK alors :
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("AD7:AD1000")) Is Nothing Then Exit Sub
Dim lig As Variant
Cancel = True
Target = Date
With Sheets("Base")
    lig = Application.Match(Cells(Target.Row, 1), .Columns("E"), 0)
    If IsNumeric(lig) Then .Range("Q" & lig).Interior.Color = Cells(Target.Row, "AR").DisplayFormat.Interior.Color
End With
End Sub
 
Juste un petit problème, j'ai déjà un code dans le BeforeDoubleClick et le deuxième code ne marche plus, comment remédier à ce problème ?
Merci pour votre aide.

VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("AD7:AD1000")) Is Nothing Then Exit Sub
Dim lig As Variant
Cancel = True
Target = Date
With Sheets("Base")
lig = Application.Match(Cells(Target.Row, 1), .Columns("E"), 0)
If IsNumeric(lig) Then .Range("Q" & lig).Interior.Color = Cells(Target.Row, "AR").DisplayFormat.Interior.Color
End With
If Not Intersect([AK6:AK600], Target) Is Nothing Then
a = Array("DCL", "")
p = Application.Match(Target, a, 0)
If IsError(p) Then
Target = a(0)
Else
If p > UBound(a) Then p = 0
Target = a(p)
End If
Cancel = True
End If
End Sub
 
Bonjour Francky79,

Bah il suffit de faire en sorte que le 1er test ne bloque pas la macro :
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("AD7:AD1000")) Is Nothing Then
    Dim lig As Variant
    Cancel = True
    Target = Date
    With Sheets("Base")
        lig = Application.Match(Cells(Target.Row, 1), .Columns("E"), 0)
        If IsNumeric(lig) Then .Range("Q" & lig).Interior.Color = Cells(Target.Row, "AR").DisplayFormat.Interior.Color
    End With
End If
If Not Intersect([AK6:AK600], Target) Is Nothing Then
    Dim a, p
    a = Array("DCL", "")
    p = Application.Match(Target, a, 0)
    If IsError(p) Then
        Target = a(0)
    Else
        If p > UBound(a) Then p = 0
        Target = a(p)
    End If
    Cancel = True
End If
End Sub
A+
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
4
Affichages
66
Réponses
34
Affichages
2 K
Réponses
38
Affichages
470
Retour