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 !

Bonjour,

Deux choses :
1. Si on fusionne des cellules, les valeurs de G3 et G14 sont effacées.
2. Ca ne fonctionne pas si il y as des formules en F12:F14. Il faut alors modifier la macro.

VB:
Private Sub Worksheet_Change(ByVal Target As Range)
'ActiveSheet.Unprotect "0000"
Dim cellule As Range
   If Not Intersect(Target, [F12:F14]) Is Nothing Then
    Application.EnableEvents = False
    If Application.CountIf([F12:F14], "- -") = 3 Then
      [G12:G14].MergeCells = True
      GoTo Fin
    End If
    If [G12:G14].MergeCells = True Then
      [G12:G14].MergeCells = False
    End If
    For Each cellule In Intersect(Target, [F12:F14])
      If cellule.Value = "- -" Then
        cellule.EntireRow.Hidden = True
      Else
        cellule.EntireRow.Hidden = False
      End If
    Next cellule
Fin:
    Application.EnableEvents = True
  End If
'ActiveSheet.Protect "0000"
End Sub

Daniel
 
Bonjour,

Deux choses :
1. Si on fusionne des cellules, les valeurs de G3 et G14 sont effacées.
2. Ca ne fonctionne pas si il y as des formules en F12:F14. Il faut alors modifier la macro.

VB:
Private Sub Worksheet_Change(ByVal Target As Range)
'ActiveSheet.Unprotect "0000"
Dim cellule As Range
   If Not Intersect(Target, [F12:F14]) Is Nothing Then
    Application.EnableEvents = False
    If Application.CountIf([F12:F14], "- -") = 3 Then
      [G12:G14].MergeCells = True
      GoTo Fin
    End If
    If [G12:G14].MergeCells = True Then
      [G12:G14].MergeCells = False
    End If
    For Each cellule In Intersect(Target, [F12:F14])
      If cellule.Value = "- -" Then
        cellule.EntireRow.Hidden = True
      Else
        cellule.EntireRow.Hidden = False
      End If
    Next cellule
Fin:
    Application.EnableEvents = True
  End If
'ActiveSheet.Protect "0000"
End Sub

Daniel
elle ne fonctionne pas ..
 
C'est ce que je t'avais dit. Comme F12:F14 contient des formules, utilise :

VB:
Private Sub Worksheet_Calculate()
Dim cellule As Range
  Application.EnableEvents = False
  If Application.CountIf([F12:F14], "- -") = 3 Then
    Application.DisplayAlerts = False
    [G12:G14].MergeCells = True
    Application.DisplayAlerts = True
    GoTo Fin
  End If
  If [G12:G14].MergeCells = True Then
    [G12:G14].MergeCells = False
  End If
  For Each cellule In [F12:F14]
    If cellule.Value = "- -" Then
      cellule.EntireRow.Hidden = True
    Else
      cellule.EntireRow.Hidden = False
    End If
  Next cellule
Fin:
  Application.EnableEvents = True
End Sub

Daniel
 
Bonjour,

Essaie :

VB:
Private Sub Worksheet_Calculate()
Dim cellule As Range
  Application.EnableEvents = False
  If Application.CountIf([F12:F14], "- -") = 3 Then
    Application.DisplayAlerts = False
    [G12:G14] = ""
    [G12:G14].MergeCells = True
    Application.DisplayAlerts = True
    GoTo Fin
  End If
  If [G12:G14].MergeCells = True Then
    [G12:G14].MergeCells = False
  End If
  For Each cellule In [F12:F14]
    If cellule.Value = "- -" Then
      cellule.EntireRow.Hidden = True
    Else
      cellule.EntireRow.Hidden = False
    End If
  Next cellule
Fin:
  Application.EnableEvents = True
End Sub
 
Oui, mais tu n'avais pas demandé de la supprimer non plus.

VB:
Private Sub Worksheet_Calculate()
Dim cellule As Range
  Application.EnableEvents = False
  If Application.CountIf([F12:F14], "- -") = 3 Then
    Application.DisplayAlerts = False
    [G12:G14] = ""
    [G12:G14].Validation.Delete
    [G12:G14].MergeCells = True
    Application.DisplayAlerts = True
    GoTo Fin
  End If
  If [G12:G14].MergeCells = True Then
    [G12:G14].MergeCells = False
  End If
  For Each cellule In [F12:F14]
    If cellule.Value = "- -" Then
      cellule.EntireRow.Hidden = True
    Else
      cellule.EntireRow.Hidden = False
    End If
  Next cellule
Fin:
  Application.EnableEvents = True
End Sub
 
- 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
5
Affichages
265
Réponses
7
Affichages
135
Réponses
18
Affichages
182
  • Question Question
Microsoft 365 format date
Réponses
3
Affichages
139
Réponses
4
Affichages
210
Retour