Conflit dans Macro (Private Sub Worksheet_BeforeDoubleClick(

Résolu
nathan01983 Messages postés 30 Date d'inscription   Statut Membre Dernière intervention   -  
nathan01983 Messages postés 30 Date d'inscription   Statut Membre Dernière intervention   -

Bonjour à toutes et à tous

J'ai un soucis de conflit .. j'ai deux macro avec le meme nom dans la meme feuille et cela me créé un conflit, et je ne sais pas comment faire pour changer le nom de l'une ou l'autre macro. 
J'ai essayé juste en ajoutant un 1 par exemple mais ca ne fonctionne pas. 
Je vous met le code, j'espère que vous pourrez m'aider. 

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  temp = Array("X", "")
  If Not Application.Intersect(Target, Range("B13:D1000,AF13:BM1000")) Is Nothing Then
    With Target
  p = Application.Match(Target, temp, 0)
  If Not IsError(p) Then
    If p = UBound(temp) + 1 Then p = 0
  Else
    p = 0
  End If
  Target = temp(p)
  Cancel = True
  End With
  End If
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
  On Error GoTo fin
  Application.EnableEvents = False
    If Not Application.Intersect(Target, Range("D10:D" & Rows.Count)) Is Nothing Then
      If Target <> "" Then
        Target.Offset(, -2).Resize(, 2) = "X"
      Else
        Target.Offset(, -2).Resize(, 2).ClearContents
      End If
    End If
fin:
  Application.EnableEvents = True
  
  If Target.Count = 1 And Target.Column = 7 Then
    Select Case Target.Value
      Case "F"
        Cells(Target.Row, 8) = "1"
      Case Else
        Cells(Target.Row, 8) = ""
      End Select
  End If
  
  If Target.Count = 1 And Target.Column = 9 Then 'Numéro de colonne de ma barre de progression
    Select Case Target.Value
      Case "1"
        Cells(Target.Row, 8) = "F"  'Numéro de colonne ou apparaitra le "f"
      
      End Select
  End If
  
End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Application.Intersect(Target, Range("H15:H2000")) Is Nothing Then Exit Sub
    Sheets("Planning").Range("h9").Value = Target.Value
    Cancel = True
End Sub

Merci à tous 

2 réponses

  1. ccm81 Messages postés 11033 Statut Membre 2 434
     

    Il ne faut pas retirer ce end if, il termine le cas où

     
    Application.Intersect(Target, Range("B13:D1000,AF13:BM1000")) n'est pas nothing

    si tu le conserves, le cas

     
    If Application.Intersect(Target, Range("H15:H2000")) Is Nothing 

    ne sera jamais examiné

    En fait, c'est le dernier end if qu'il faut supprimer !

    Et comme ça ce sera plus clair

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
      temp = Array("X", "")
      If Not Application.Intersect(Target, Range("B13:D1000,AF13:BM1000")) Is Nothing Then
        With Target
          p = Application.Match(Target, temp, 0)
          If Not IsError(p) Then
            If p = UBound(temp) + 1 Then p = 0
          Else
            p = 0
          End If
          Target = temp(p)
          Cancel = True
        End With
      End If '(Je l'ai retiré)
      If Not Application.Intersect(Target, Range("H15:H2000")) Is Nothing Then
        Sheets("Planning").Range("h9").Value = Target.Value
        Cancel = True
      End If
    End Sub

    Cdlmnt

    1
    1. nathan01983 Messages postés 30 Date d'inscription   Statut Membre Dernière intervention   10
       

      Parfait. Merci encore BCP 

      0
  2. ccm81 Messages postés 11033 Statut Membre 2 434
     

    Bonjour

    Essaies comme ça avec une seule procedure BeforeDoubleClick

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
      temp = Array("X", "")
      If Not Application.Intersect(Target, Range("B13:D1000,AF13:BM1000")) Is Nothing Then
        With Target
          p = Application.Match(Target, temp, 0)
          If Not IsError(p) Then
            If p = UBound(temp) + 1 Then p = 0
          Else
            p = 0
          End If
          Target = temp(p)
          Cancel = True
        End With
      End If
      If Application.Intersect(Target, Range("H15:H2000")) Is Nothing Then Exit Sub
        Sheets("Planning").Range("h9").Value = Target.Value
        Cancel = True
      End If
    End Sub

    Cdlmnt

    0
    1. nathan01983 Messages postés 30 Date d'inscription   Statut Membre Dernière intervention   10
       

      Bonjour Merci pour ton aide (ENCORE une fois ;) )

      J'ai ce message d'erreur 

      "Erreur de compilation :

      End If sans bloc If"

      0
      1. nathan01983 Messages postés 30 Date d'inscription   Statut Membre Dernière intervention   10 > nathan01983 Messages postés 30 Date d'inscription   Statut Membre Dernière intervention  
         
        Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
          temp = Array("X", "")
          If Not Application.Intersect(Target, Range("B13:D1000,AF13:BM1000")) Is Nothing Then
            With Target
              p = Application.Match(Target, temp, 0)
              If Not IsError(p) Then
                If p = UBound(temp) + 1 Then p = 0
              Else
                p = 0
              End If
              Target = temp(p)
              Cancel = True
            End With
          'End If (Je l'ai retiré)
          If Application.Intersect(Target, Range("H15:H2000")) Is Nothing Then Exit Sub
            Sheets("Planning").Range("h9").Value = Target.Value
            Cancel = True
          End If
        End Sub

        Le double clic (la premiere partie fontionne) mais le copie cellule lui ne fonctionne pas. 

        0