Comment colorer les cellules quand je saisis dans différentes colonnes ?

anthoYS

XLDnaute Barbatruc
Bonjour,


Par exemple, en B, D, F et G uniquement.
Si je saisi des données, eh bien colorer en fond vert.


.Interior.ColorIndex = 4
(mais après, mystères, "ActiveCells.Row(2)" ?)


Merci !
à+
 

DoubleZero

XLDnaute Barbatruc
Bonjour à toutes et à tous,

Peut-être ainsi :
VB:
Option Explicit
Private Sub Worksheet_Change(ByVal c As Range)
    Dim plage As Range
    Set plage = Range("B:B,D:D,F:F,G:G")
    If c.Count > 1 Then Exit Sub
    If Not Intersect(c, plage) Is Nothing Then
        Select Case c
        Case Is <> "": c.Interior.ColorIndex = 4: Case Else: c.Interior.ColorIndex = xlNone
        End Select
    End If
End Sub
A bientôt :)
 

anthoYS

XLDnaute Barbatruc
Re,


Merci @DoubleZero

j'ai déjà ce code dans la page, je veux l'agréger, et fatalement il y a une erreur, je continue de chercher...

VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
With Target
    If .Column = 2 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 241.5
            .Comment.Shape.Height = 99.75
        End If
        SendKeys "%im"
    End If
     If .Column = 3 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 241.5
            .Comment.Shape.Height = 99.75
        End If
        SendKeys "%im"
    End If
     If .Column = 4 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 241.5
            .Comment.Shape.Height = 99.75
        End If
        SendKeys "%im"
    End If
     If .Column = 5 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 241.5
            .Comment.Shape.Height = 99.75
        End If
        SendKeys "%im"
    End If
     If .Column = 6 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 241.5
            .Comment.Shape.Height = 99.75
        End If
        SendKeys "%im"
    End If
     If .Column = 7 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 241.5
            .Comment.Shape.Height = 99.75
        End If
        SendKeys "%im"
    End If
     If .Column = 8 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 241.5
            .Comment.Shape.Height = 99.75
        End If
        SendKeys "%im"
    End If
     If .Column = 9 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 241.5
            .Comment.Shape.Height = 99.75
        End If
        SendKeys "%im"
    End If
End With
With Target
    If .Column = 4 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 279.5
            .Comment.Shape.Height = 130.75
        End If
        SendKeys "%im"
    End If
End With
End Sub

Si je n'y parviens pas, je reviens avec ce que j'ai fait de ton code et de ce dernier.

@Marcel32 , pour ce qui est de la MFC je ne vois pas ?
 
Dernière édition:

DoubleZero

XLDnaute Barbatruc
Re-bonjour,
... j'ai déjà ce code...
Que donnerait celui-ci ?
VB:
Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    With Target
        If .Column > 1 And .Column < 10 Then
            If .Comment Is Nothing Then
                .AddComment
                .Comment.Shape.Width = 241.5
                .Comment.Shape.Height = 99.75
            SendKeys "%im"
        End If
    End If
End With
Application.SendKeys "{NUMLOCK}", True ' clavier numérique activer
End Sub
A bientôt :)
 

Discussions similaires

Statistiques des forums

Discussions
312 190
Messages
2 086 040
Membres
103 105
dernier inscrit
fofana