Sub Test1()Met DEJA en évidence une condition If sans End If !
ChDir "M:\MARC\Facture-Gab\Fact-Synth\"
DossierFactures = Dir("M:\MARC\Facture-Gab\Fact-Synth\*.xlsx")
'Début boucle trim1
Dim j As Integer
j = 12
Do While Len(DossierFactures) > 0
'ouverture dossier facture
Workbooks.Open "M:\MARC\Facture-Gab\Fact-Synth\" & DossierFactures
If Range("B13") < 4 = True Then
'traitement data
Dim plage As Range, desti As Range, i As Integer
Set desti = Workbooks("Synth-Test.xlsm").Worksheets("Feuil1").Range("B" & j)
Set plage = Range("G6, H33,I34, J35")
For i = 1 To plage.Areas.Count
desti.Offset(0, i - 1).Value = plage.Areas(i).Value
Next
Workbooks("Synth-Test.xlsm").Worksheets("Feuil1").Range("A" & j) = DossierFactures
'fermeture classeur xlsx
Workbooks(DossierFactures).Saved = True
Workbooks(DossierFactures).Close
DossierFactures = Dir
j = j + 1
Else:
'boucle trim2
If Range("B13") < 7 = True Then
'traitement data
Set desti = Workbooks("Synth-Test.xlsm").Worksheets("Feuil2").Range("B" & j)
Set plage = Range("G6, H33,I34, J35")
For i = 1 To plage.Areas.Count
desti.Offset(0, i - 1).Value = plage.Areas(i).Value
Next
Workbooks("Synth-Test.xlsm").Worksheets("Feuil2").Range("A" & j) = DossierFactures
'fermeture classeur xlsx
Workbooks(DossierFactures).Saved = True
Workbooks(DossierFactures).Close
DossierFactures = Dir
j = j + 1
Else: End If
Loop
Columns("A:A").Replace ".xlsx", ""
End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionSub Test1()
ChDir "M:\MARC\Facture-Gab\Fact-Synth\"
DossierFactures = Dir("M:\MARC\Facture-Gab\Fact-Synth\*.xlsx")
Dim j As Integer, k As Integer
j = 12
'Début boucle principale
Do While Len(DossierFactures) > 0
'ouverture dossier facture
Workbooks.Open "M:\MARC\Facture-Gab\Fact-Synth\" & DossierFactures
k = Range("B13").Value
'boucle trim1
If k <= 3 = True Then
'traitement data
Dim plage As Range, desti As Range, i As Integer
Set desti = Workbooks("Synth-Test.xlsm").Worksheets("Feuil1").Range("B" & j)
Set plage = Range("G6, H33,I34, J35")
For i = 1 To plage.Areas.Count
desti.Offset(0, i - 1).Value = plage.Areas(i).Value
Next
Workbooks("Synth-Test.xlsm").Worksheets("Feuil1").Range("A" & j) = DossierFactures
'fermeture classeur xlsx
Workbooks(DossierFactures).Saved = True
Workbooks(DossierFactures).Close
DossierFactures = Dir
j = j + 1
ElseIf k > 3 = True Then
'boucle trim2
'traitement data
Set desti = Workbooks("Synth-Test.xlsm").Worksheets("Feuil2").Range("B" & j)
Set plage = Range("G6, H33,I34, J35")
For i = 1 To plage.Areas.Count
desti.Offset(0, i - 1).Value = plage.Areas(i).Value
Next
Workbooks("Synth-Test.xlsm").Worksheets("Feuil2").Range("A" & j) = DossierFactures
'fermeture classeur xlsx
Workbooks(DossierFactures).Saved = True
Workbooks(DossierFactures).Close
DossierFactures = Dir
j = j + 1
Columns("A:A").Replace ".xlsx", ""
Loop
End Sub
toto = 12Tu le vois, ton fameux message d'erreur ? Oui, n'est-ce-pas ? Il est dû dans ce tout petit exemple à une mauvaise syntaxe (incomplète) des expressions conditionnelles qui y figurent.
titi = 1
Do While toto > -1
If titi = 1 Then
tata = 2
Else
If titi = 2 Then
tata = 3
toto = toto - tata
MsgBox toto
Loop
Sub Test1()
ChDir "M:\MARC\Facture-Gab\Fact-Synth\"
DossierFactures = Dir("M:\MARC\Facture-Gab\Fact-Synth\*.xlsx")
Dim j As Integer, k As Integer
j = 12
'Début boucle principale
Do While Len(DossierFactures) > 0
'ouverture dossier facture
Workbooks.Open "M:\MARC\Facture-Gab\Fact-Synth\" & DossierFactures
k = Range("B13").Value
'boucle trim1
If k <= 3 Then
'traitement data
Dim plage As Range, desti As Range, i As Integer
Set desti = Workbooks("Synth-Test.xlsm").Worksheets("Feuil1").Range("B" & j)
Set plage = Range("G6, H33,I34, J35")
For i = 1 To plage.Areas.Count
desti.Offset(0, i - 1).Value = plage.Areas(i).Value
Next
Workbooks("Synth-Test.xlsm").Worksheets("Feuil1").Range("A" & j) = DossierFactures
'fermeture classeur xlsx
Workbooks(DossierFactures).Saved = True
Workbooks(DossierFactures).Close
DossierFactures = Dir
j = j + 1
Else: End If
Columns("A:A").Replace ".xlsx", ""
Loop
End Sub
toto = 12que l'on pourrait également écrire ainsi :
titi = 1
Do While toto > -1
If titi = 1 Then
tata = 2
Else
If titi = 2 Then
tata = 3
End If
End If
toto = toto - tata
MsgBox toto
Loop
toto = 12Lis, analyse, comprends et applique à ton "cas".
titi = 1
Do While toto > -1
If titi = 1 Then
tata = 2
ElseIf titi = 2 Then
tata = 3
End If
toto = toto - tata
MsgBox toto
Loop
Sub Test1()
ChDir "M:\MARC\Facture-Gab\Fact-Synth\"
DossierFactures = Dir("M:\MARC\Facture-Gab\Fact-Synth\*.xlsx")
Dim j As Integer, k As Integer, l As Integer
j = 12
l = 12
'Début boucle principale
Do While Len(DossierFactures) > 0
'ouverture dossier facture
Workbooks.Open "M:\MARC\Facture-Gab\Fact-Synth\" & DossierFactures
k = Range("B13").Value
'boucle trim1
If k <= 3 Then
'traitement data
Dim plage As Range, desti As Range, i As Integer
Set desti = Workbooks("Synth-Test.xlsm").Worksheets("Feuil1").Range("B" & j)
Set plage = Range("G6, H33,I34, J35")
For i = 1 To plage.Areas.Count
desti.Offset(0, i - 1).Value = plage.Areas(i).Value
Next
Workbooks("Synth-Test.xlsm").Worksheets("Feuil1").Range("A" & j) = DossierFactures
'fermeture classeur xlsx
Workbooks(DossierFactures).Saved = True
Workbooks(DossierFactures).Close
DossierFactures = Dir
j = j + 1
ElseIf k > 3 Then
'boucle trim2
'traitement data
Set desti = Workbooks("Synth-Test.xlsm").Worksheets("Feuil2").Range("B" & l)
Set plage = Range("G6, H33,I34, J35")
For i = 1 To plage.Areas.Count
desti.Offset(0, i - 1).Value = plage.Areas(i).Value
Next
Workbooks("Synth-Test.xlsm").Worksheets("Feuil2").Range("A" & l) = DossierFactures
'fermeture classeur xlsx
Workbooks(DossierFactures).Saved = True
Workbooks(DossierFactures).Close
DossierFactures = Dir
l = l + 1
End If
Loop
End Sub
Sub Test1()
Dim plage As Range, desti As Range, i As Integer, dossier As String, classeurs As String
Dim cldesti As Workbook, plage As Range, desti As Range, lafeuille As String, derlig As Long
dossier = "M:\MARC\Facture-Gab\Fact-Synth\"
classeurs = Dir(dossier & "*.xlsx")
Set cldesti = Workbooks("Synth-Test.xlsm")
Do While Len(classeurs) > 0
Workbooks.Open classeurs
lafeuille = "Feuil" & Int((Range("B13").Value + 2) / 3)
derlig = Worksheets(lafeuille).Range("B12:B" & Rows.Count).SpecialCells(xlCellTypeBlanks).Row
Set desti = cldesti.Worksheets(lafeuille).Range("B" & derlig)
Set plage = Range("G6, H33,I34, J35")
For i = 1 To plage.Areas.Count
desti.Offset(0, i - 1).Value = plage.Areas(i).Value
Next
cldesti.Worksheets(lafeuille).Range("A" & derlig) = classeurs
Workbooks(classeurs).Saved = True
Workbooks(classeurs).Close
classeurs = Dir
Loop
End Sub
Workbooks.Open dossier & classeursLa seconde est plus gênante car elle laisse supposer une feuille d'un nom inexistant, probablement Feuil0.
toto = Int((Range("B13").Value + 2) / 3)
If toto = 0 Or toto > 4 Then MsgBox "B13 avec donnée incompatible dans classeur " & classeurs