Ouverture de macro vba sur un nouveau poste

Résolu/Fermé
Co_nexion Messages postés 328 Date d'inscription lundi 5 mars 2012 Statut Membre Dernière intervention 15 juillet 2015 - Modifié par Co_nexion le 18/06/2012 à 21:30
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 - 19 juin 2012 à 10:05
Bonjour à tous,

Je me retrouve bloqué en voulant utilisé mes macros sur un nouveau poste et pourtant les deux sont en excel 2010 et sous seven.

Voici le code et en gras la ligne qui bloque (IF DCLA > 1 then). Le message d'erreur est bibliothèque ou projet introuvable.

Pourriez vous m'aider à comprendre ce blocage ?

'Mettre à jour les cycles  
Dim Derlig As Long, i As Long  
     
    With Sheets("FTP")  
      Derlig = .Range("L" & Rows.Count).End(xlUp).Row  
      For i = 2 To Derlig  
        'If .Range("N" & i) < .Range("W" & i) Then  
        ' ou  
        If .Cells(i, 14) < .Cells(1, 23) Then  
          .Range("L" & i) = .Range("N" & i) + 1  
          ' ou  
          '.Cells(i, 12) = .Cells(i, 14) + 1  
          .Range("N" & i) = .Range("L" & i) + .Range("M" & i)  
          ' ou  
          '.Cells(i, 14) = .Cells(i, 12) + .Cells(i, 13)  
        End If  
      Next i  
    End With  

'Test pour contrat(s) mois en cours  
'pour la dernière ligne de la colonne A  
'DCLA = Worksheets("CDD_Fin_de_Contrat").Range("A" & Rows.Count).End(xlUp).Row  
  If DCLA > 1 Then  
      
'Worksheets("CDD_Fin_de_Contrat").Range("A2:N" & DCLA).ClearContents  
    Worksheets("CDD_Fin_de_Contrat").Range("A2:N29").ClearContents  
  End If  
    
'pour la dernière ligne de la colonne A  
  DCLA = Worksheets("CDD").Range("A" & Rows.Count).End(xlUp).Row  
  ReDim NumLigne(DCLA)  
'Copie donnees pour tri et listbox  
  Worksheets("CDD_Fin_de_Contrat").Range("A2:N" & DCLA) = Worksheets("CDD").Range("A2:N" & DCLA).Value  
'Mois pour test  
  Mois_Courant = Format(Date, "mm")  
'Pointeur pour recherche  
  x = 2  
  Rangee = 2  
  Worksheets("CDD_Fin_de_Contrat").Activate  
  Application.ScreenUpdating = False  
  With Worksheets("CDD_Fin_de_Contrat")  
    Do While .Cells(x, "G") <> ""  
      If Format(CDate(.Cells(x, "G")), "mm") <> Mois_Courant Then  
        Rows(x & ":" & x).Delete xlUp  
        x = x - 1  
      Else  
        NumLigne(x - 2) = Rangee  
      End If  
      x = x + 1  
      Rangee = Rangee + 1  
    Loop  

'pour la dernière ligne de la colonne A  
    DCLA = .Range("A" & Rows.Count).End(xlUp).Row  
'Fin selection  
    If DCLA = 1 And .Range("A2") = "" Then  
      Me.CommandButton9.Enabled = False  
      Exit Sub  
    Else  
      Me.CommandButton9.Enabled = True  
    End If  
  End With  
  Application.ScreenUpdating = True  

End Sub




A voir également:

1 réponse

pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 743
Modifié par pijaku le 19/06/2012 à 10:06
Bonjour,
Si DCLA est une variable, avant de tester (If DCLA > 1), il te faut :
1- la déclarer,
2- lui affecter une valeur.
Dans ton cas, DCLA est une valeur numérique donc de type Long (le nombre de ligne pouvant en effet être trop important pour une variable de type Integer, surtout depuis les versions > 2007), de plus, tu as laissé l'apostrophe en début de la ligne ou tu affectes une valeur à DCLA, donc essaye (les modifs en gras) :

'Mettre à jour les cycles   
Dim Derlig As Long, i As Long, DCLA As Long      
    With Sheets("FTP")   
      Derlig = .Range("L" & Rows.Count).End(xlUp).Row   
      For i = 2 To Derlig   
        'If .Range("N" & i) < .Range("W" & i) Then   
        ' ou   
        If .Cells(i, 14) < .Cells(1, 23) Then   
          .Range("L" & i) = .Range("N" & i) + 1   
          ' ou   
          '.Cells(i, 12) = .Cells(i, 14) + 1   
          .Range("N" & i) = .Range("L" & i) + .Range("M" & i)   
          ' ou   
          '.Cells(i, 14) = .Cells(i, 12) + .Cells(i, 13)   
        End If   
      Next i   
    End With   

'Test pour contrat(s) mois en cours   
'pour la dernière ligne de la colonne A   
DCLA = Worksheets("CDD_Fin_de_Contrat").Range("A" & Rows.Count).End(xlUp).Row
     If DCLA > 1 Then   
       
'Worksheets("CDD_Fin_de_Contrat").Range("A2:N" & DCLA).ClearContents   
    Worksheets("CDD_Fin_de_Contrat").Range("A2:N29").ClearContents   
  End If   
     
'pour la dernière ligne de la colonne A   
  DCLA = Worksheets("CDD").Range("A" & Rows.Count).End(xlUp).Row   
  ReDim NumLigne(DCLA)   
'Copie donnees pour tri et listbox   
  Worksheets("CDD_Fin_de_Contrat").Range("A2:N" & DCLA) = Worksheets("CDD").Range("A2:N" & DCLA).Value   
'Mois pour test   
  Mois_Courant = Format(Date, "mm")   
'Pointeur pour recherche   
  x = 2   
  Rangee = 2   
  Worksheets("CDD_Fin_de_Contrat").Activate   
  Application.ScreenUpdating = False   
  With Worksheets("CDD_Fin_de_Contrat")   
    Do While .Cells(x, "G") <> ""   
      If Format(CDate(.Cells(x, "G")), "mm") <> Mois_Courant Then   
        Rows(x & ":" & x).Delete xlUp   
        x = x - 1   
      Else   
        NumLigne(x - 2) = Rangee   
      End If   
      x = x + 1   
      Rangee = Rangee + 1   
    Loop   

'pour la dernière ligne de la colonne A   
    DCLA = .Range("A" & Rows.Count).End(xlUp).Row   
'Fin selection   
    If DCLA = 1 And .Range("A2") = "" Then   
      Me.CommandButton9.Enabled = False   
      Exit Sub   
    Else   
      Me.CommandButton9.Enabled = True   
    End If   
  End With   
  Application.ScreenUpdating = True   

End Sub


Cordialement,
Franck P
0