Microsoft 365 changement couleur cellule au survol de la souris

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 !

josianejbg

XLDnaute Nouveau
Bonjour à tous,
Je suis nouvelle et d'ores et déjà j'aimerai avoir votre aide.
Je fais beaucoup de tableaux avec excel et je souhaiterai, lors du survol avec la souris ou avec les touches direction clavier, que la cellule change de couleur mais dès que je passe à une autre cellule, la première reprend sa couleur initiale.
J'ai tenté des solutions mais hélas ça ne fait pas comme je veux ( entre autre la couleur ne revient pas à sa couleur initiale).
Je ne suis pas une pro, alors SVPM, une procèdure à faire pas à pas .
d'avance merci
bonne journée
 
Solution
VB:
Option Explicit
Dim oldcell As Range
Dim chang As Boolean

Private Sub Workbook_BeforeClose(Cancel As Boolean)
        If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
        Application.OnKey "{UP}"
        Application.OnKey "{DOWN}"
        Application.OnKey "{LEFT}"
        Application.OnKey "{RIGHT}"
End Sub

Private Sub Workbook_Open(): detourneTouche: End Sub
Public Sub updownleftright(arg As String)
    chang = True
    Select Case arg
    Case "{UP}": If ActiveCell.Row > 1 Then ActiveCell.Offset(-1).Select
    Case "{DOWN}": If ActiveCell.Row < Rows.Count Then ActiveCell.Offset(1).Select
    Case "{LEFT}": If ActiveCell.Column > 1 Then ActiveCell.Offset(, -1).Select
    Case "{RIGHT}": If ActiveCell.Column <...
re
un exemple
ouvre un nouveau classeur et colle tout ce code dans le module "ThisWorkBook"
VB:
Option Explicit
Dim oldcell As Range
Dim chang As Boolean
Private Sub Workbook_Open(): detourneTouche: End Sub
Public Sub updownleftright(arg As String)
    chang = True
    Select Case arg
    Case "{UP}": If ActiveCell.Row > 1 Then ActiveCell.Offset(-1).Select
    Case "{DOWN}": If ActiveCell.Row < Rows.Count Then ActiveCell.Offset(1).Select
    Case "{LEFT}": If ActiveCell.Column > 1 Then ActiveCell.Offset(, -1).Select
    Case "{RIGHT}": If ActiveCell.Column < Columns.Count Then ActiveCell.Offset(, 1).Select
    End Select
End Sub
Sub detourneTouche()
    If ActiveSheet.Index = 1 Then
        Application.OnKey "{UP}", "'ThisWorkBook.updownleftright ""{UP}""'"
        Application.OnKey "{DOWN}", "'ThisWorkBook.updownleftright ""{DOWN}""'"
        Application.OnKey "{LEFT}", "'ThisWorkBook.updownleftright ""{LEFT}""'"
        Application.OnKey "{RIGHT}", "'ThisWorkBook.updownleftright ""{RIGHT}""'"
    Else
        If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
        Application.OnKey "{UP}"
        Application.OnKey "{DOWN}"
        Application.OnKey "{LEFT}"
        Application.OnKey "{RIGHT}"
    End If
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object): detourneTouche: End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
    If Sh.Index = 1 Then
        If chang = True Then
            Target.Interior.Color = vbRed
            Set oldcell = Target
            chang = False
        End If
    End If
End Sub
et promène toi avec les flèches
j'ai bridé l'effet sur la feuille 1
😉
 
Bonjour
Il me semble qu'il y ait pas d'exemple sur le web !!!! ....en cherchant un peu ?
sinon il y a cette solution qui fonctionne mais à adapter à ton fichier puisque ....... pas joint ici !
Il est pas évident à comprendre , je te laisse l'astuce principale d ela feuille1 , un textbox superpose la cellule remet la bien en place ( se mettre en mode création), enregistre et re passe la souris normalement c'est vert puis revient à l'origine si tu cliques tu vas à la feuille avec le nom
C'est pas évident à comprendre , le pas à pas en debug ne marche pas ( cause événement)
A toi de jouer avec ......et de la patience
 

Pièces jointes

re
un exemple
ouvre un nouveau classeur et colle tout ce code dans le module "ThisWorkBook"
VB:
Option Explicit
Dim oldcell As Range
Dim chang As Boolean
Private Sub Workbook_Open(): detourneTouche: End Sub
Public Sub updownleftright(arg As String)
    chang = True
    Select Case arg
    Case "{UP}": If ActiveCell.Row > 1 Then ActiveCell.Offset(-1).Select
    Case "{DOWN}": If ActiveCell.Row < Rows.Count Then ActiveCell.Offset(1).Select
    Case "{LEFT}": If ActiveCell.Column > 1 Then ActiveCell.Offset(, -1).Select
    Case "{RIGHT}": If ActiveCell.Column < Columns.Count Then ActiveCell.Offset(, 1).Select
    End Select
End Sub
Sub detourneTouche()
    If ActiveSheet.Index = 1 Then
        Application.OnKey "{UP}", "'ThisWorkBook.updownleftright ""{UP}""'"
        Application.OnKey "{DOWN}", "'ThisWorkBook.updownleftright ""{DOWN}""'"
        Application.OnKey "{LEFT}", "'ThisWorkBook.updownleftright ""{LEFT}""'"
        Application.OnKey "{RIGHT}", "'ThisWorkBook.updownleftright ""{RIGHT}""'"
    Else
        If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
        Application.OnKey "{UP}"
        Application.OnKey "{DOWN}"
        Application.OnKey "{LEFT}"
        Application.OnKey "{RIGHT}"
    End If
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object): detourneTouche: End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
    If Sh.Index = 1 Then
        If chang = True Then
            Target.Interior.Color = vbRed
            Set oldcell = Target
            chang = False
        End If
    End If
End Sub
et promène toi avec les flèches
j'ai bridé l'effet sur la feuille 1
😉
PARFAIT CA MARCHE MERCI.
Par contre quand je ferme mon fichier et le réouvre, il faut refaire toute la procédure, est-ce normal ?
merci
 
VB:
Option Explicit
Dim oldcell As Range
Dim chang As Boolean

Private Sub Workbook_BeforeClose(Cancel As Boolean)
        If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
        Application.OnKey "{UP}"
        Application.OnKey "{DOWN}"
        Application.OnKey "{LEFT}"
        Application.OnKey "{RIGHT}"
End Sub

Private Sub Workbook_Open(): detourneTouche: End Sub
Public Sub updownleftright(arg As String)
    chang = True
    Select Case arg
    Case "{UP}": If ActiveCell.Row > 1 Then ActiveCell.Offset(-1).Select
    Case "{DOWN}": If ActiveCell.Row < Rows.Count Then ActiveCell.Offset(1).Select
    Case "{LEFT}": If ActiveCell.Column > 1 Then ActiveCell.Offset(, -1).Select
    Case "{RIGHT}": If ActiveCell.Column < Columns.Count Then ActiveCell.Offset(, 1).Select
    End Select
End Sub
Sub detourneTouche()
        Application.OnKey "{UP}", "'ThisWorkBook.updownleftright ""{UP}""'"
        Application.OnKey "{DOWN}", "'ThisWorkBook.updownleftright ""{DOWN}""'"
        Application.OnKey "{LEFT}", "'ThisWorkBook.updownleftright ""{LEFT}""'"
        Application.OnKey "{RIGHT}", "'ThisWorkBook.updownleftright ""{RIGHT}""'"
 End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object): If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
 End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
         If chang = True Then
            Target.Interior.Color = vbRed
            Set oldcell = Target
            chang = False
        End If
   End Sub
 
VB:
Option Explicit
Dim oldcell As Range
Dim chang As Boolean

Private Sub Workbook_BeforeClose(Cancel As Boolean)
        If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
        Application.OnKey "{UP}"
        Application.OnKey "{DOWN}"
        Application.OnKey "{LEFT}"
        Application.OnKey "{RIGHT}"
End Sub

Private Sub Workbook_Open(): detourneTouche: End Sub
Public Sub updownleftright(arg As String)
    chang = True
    Select Case arg
    Case "{UP}": If ActiveCell.Row > 1 Then ActiveCell.Offset(-1).Select
    Case "{DOWN}": If ActiveCell.Row < Rows.Count Then ActiveCell.Offset(1).Select
    Case "{LEFT}": If ActiveCell.Column > 1 Then ActiveCell.Offset(, -1).Select
    Case "{RIGHT}": If ActiveCell.Column < Columns.Count Then ActiveCell.Offset(, 1).Select
    End Select
End Sub
Sub detourneTouche()
        Application.OnKey "{UP}", "'ThisWorkBook.updownleftright ""{UP}""'"
        Application.OnKey "{DOWN}", "'ThisWorkBook.updownleftright ""{DOWN}""'"
        Application.OnKey "{LEFT}", "'ThisWorkBook.updownleftright ""{LEFT}""'"
        Application.OnKey "{RIGHT}", "'ThisWorkBook.updownleftright ""{RIGHT}""'"
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object): If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    If Not oldcell Is Nothing Then oldcell.Interior.Color = xlNone
         If chang = True Then
            Target.Interior.Color = vbRed
            Set oldcell = Target
            chang = False
        End If
   End Sub
SUPER ENCORE MILLE MERCI
JE NE VOUS EMBETE PLUS - TOUT MARCHE A MERVEILLE
 
- 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

Retour