Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

aide à la correction de macro

  • Initiateur de la discussion Initiateur de la discussion bpol
  • Date de début Date de début

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 !

bpol

XLDnaute Impliqué
bonjour,

j'ai une macro que j'ai mdifiée mais elle ne veux pas fonctionner !!


Sub enregistrer()
'
' enregistrer Macro
' Macro enregistrée le 14/03/2008 par POLAIN
'
'Private Sub cmdEnregistrer_Click()
Dim lig As Long
Dim choixLig As Long
Dim col As Long
Dim choixCol As Long

' Trouver la ligne
choixLig = 0

For lig = 7 To 256
If Range("E7") = 0 Then choixLig = 7: Exit For

If Range("E" & lig) = Range("E1") Then choixLig = lig: Exit For

If Range("E" & lig) = 0 And Range("F3") > 1 Then
lig = Range("E65536").End(xlUp).Row + 1
Cells(lig, 5) = Range("E1")
choixLig = lig: Exit For
End If
Next lig

Cells(choixLig, 5) = Range("E1")

' If choixLig = 0 Then
' MsgBox "L'enregistrement n'est pas possible", vbCritical + vbOKOnly, "Erreur"
' Exit Sub
' End If

' Trouver la colonne
choixCol = 0
For col = 6 To 9
If Cells(choixLig, col) = 0 Then
choixCol = col
Exit For
End If
Next col

If choixCol = 0 Then
MsgBox "L'enregistrement n'est pas possible", vbCritical + vbOKOnly, "Erreur"
Exit Sub
End If

' Afficher le résultat
Cells(choixLig, choixCol).Value = Range("I1").Value

'and
Sheets("récap").Select
Ligne = Range("A65536").End(xlUp).Row + 1
Cells(Ligne, 1) = Sheets("tableau").Range("E1")
Cells(Ligne, 2) = Sheets("tableau").Range("H1")
Cells(Ligne, 3) = Sheets("tableau").Range("G1")
Cells(Ligne, 4) = Sheets("tableau").Range("I1")
'and
Workbooks("tempsmmss").Select
Ligne = Range("A65536").End(xlUp).Row + 1
Cells(Ligne, 1) = Sheets("tableau").Range("E1")
Cells(Ligne, 2) = Sheets("tableau").Range("I1")
Cells(Ligne, 3) = Sheets("tableau").Range("H1")
Cells(Ligne, 4) = Sheets("tableau").Range("G1")
'and
Workbooks("Prog2mmss_ok4.xls").Worksheets("tableau").Select
'And
ActiveWorkbook.save
'
End Sub


j'ai essayé plusieurs corrections sans résultats !!

merci Bpol
 
Re : aide à la correction de macro

Salut Bpol,

Dans l'état actuelle de la chose, difficile de t'aider 😕
A part supprimer les 2 lignes en jaune, qui doivent poser problème

Sinon joint nous le fichier et dis nous exactement ce que tu souhaiterais,
et ce que tu as pour le moment.

A+
 
Re : aide à la correction de macro

Bonjour


Ton classeur contient plusieurs modules vides.

(Tu pourrais les supprimer, cela allègera ton fichier)

Si tu crées un fichier zip par fichier xls
tu pourras directement les joindre ici sur le forum


A+
 
Re : aide à la correction de macro

Bonjour,

Essayez de voir si le code suivant apporte un progrès.
J'avoue ne pas très bien comprendre votre problème.

Code:
Sub enregistrer_pmo()
Dim WB1 As Workbook
Dim WB2 As Workbook
Dim lig As Long
Dim choixLig As Long
Dim col As Long
Dim choixCol As Long
Dim Ligne As Long
  
Set WB1 = ActiveWorkbook
Sheets("tableau").Activate   '????? est-ce bien cette feuille ?????
' Trouver la ligne
choixLig = 0
   
For lig = 7 To 256
 If Range("E7") = 0 Then choixLig = 7: Exit For

 If Range("E" & lig) = Range("E1") Then choixLig = lig: Exit For
 
 If Range("E" & lig) = 0 And Range("F3") > 1 Then
 lig = Range("E65536").End(xlUp).Row + 1
 Cells(lig, 5) = Range("E1")
 choixLig = lig: Exit For
 End If
Next lig
  
Cells(choixLig, 5) = Range("E1")

'    If choixLig = 0 Then
'        MsgBox "L'enregistrement n'est pas possible", vbCritical + vbOKOnly, "Erreur"
'        Exit Sub
'    End If
    
    ' Trouver la colonne
choixCol = 0
For col = 6 To 9
  If Cells(choixLig, col) = 0 Then
    choixCol = col
    Exit For
  End If
Next col
  
If choixCol = 0 Then
  MsgBox "L'enregistrement n'est pas possible", vbCritical + vbOKOnly, "Erreur"
  Exit Sub
End If
    
  ' Afficher le résultat
Cells(choixLig, choixCol).Value = Range("I1").Value
    
'and
Sheets("récap").Select
Ligne = Range("A65536").End(xlUp).Row + 1
Cells(Ligne, 1) = Sheets("tableau").Range("E1")
Cells(Ligne, 2) = Sheets("tableau").Range("H1")
Cells(Ligne, 3) = Sheets("tableau").Range("G1")
Cells(Ligne, 4) = Sheets("tableau").Range("I1")
    'and
Windows("tempsmmss.xls").Activate
Set WB2 = ActiveWorkbook

Ligne = Range("A65536").End(xlUp).Row + 1
Cells(Ligne, 1) = WB1.Sheets("tableau").Range("E1")
Cells(Ligne, 2) = WB1.Sheets("tableau").Range("H1")
Cells(Ligne, 3) = WB1.Sheets("tableau").Range("G1")
Cells(Ligne, 4) = WB1.Sheets("tableau").Range("I1")
    'and
Windows("Prog2mmss_ok4.xls").Activate
Worksheets("tableau").Select
'And
WB1.Save
WB2.Save
'
End Sub

Cordialement.

PMO
Patrick Morange
 
- 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
4
Affichages
743
Réponses
5
Affichages
931
Réponses
4
Affichages
764
Réponses
4
Affichages
287
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…