1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| Sub Importer()
'Réf Source.xls legenuis
Dim Fich As String, Chemin As String, Wb As Workbook
Dim c As Range, Teste As Variant, Plage As Range, Ligne As Long
Dim Col As Integer
With ThisWorkbook.Sheets("Total")
Set Plage = .Range(.[B5], .Cells(.Rows.Count, 2).End(xlUp))
End With
Chemin = ThisWorkbook.Path '*** à modifier éventuellement
Fich = Dir(Chemin & "\*.xls")
Do While Fich <> ""
If LCase(Left(Fich, 6)) = "client" Then '*** à modifier éventuellement
With ThisWorkbook.Sheets("Total")
Set Wb = Workbooks.Open(Chemin & "\" & Fich)
'****Traitement de la feuille Total
For Each c In Range([B5], Cells(Rows.Count, 2).End(xlUp))
If c.Offset(, -1) <> 0 Then
Teste = Application.Match(c.Value, Plage, 0)
If IsNumeric(Teste) Then
Teste = Teste + 4
For i = 3 To 14
.Cells(Teste, i).Value = .Cells(Teste, i).Value + Cells(c.Row, i).Value
Next i
Else
Ligne = .Cells(.Rows.Count, 2).End(xlUp).Offset(1).Row
Range(Cells(c.Row, 1), Cells(c.Row, 14)).Copy .Cells(Ligne, 1)
End If
Else
Range(Cells(c.Row, 1), Cells(c.Row, 14)).Font.Strikethrough = True
End If
Next c
End With
'****Traitement de la feuille Recap
With ThisWorkbook.Sheets("Recap")
Set Plage = .Range(.[B5], .Cells(.Rows.Count, 2).End(xlUp))
For Each c In Range([B5], Cells(Rows.Count, 2).End(xlUp))
If c.Offset(, -1) <> 0 Then
Col = Application.Match([B2].Value, .Rows(3), 0)
Teste = Application.Match(c.Value, Plage, 0)
If IsNumeric(Teste) Then
Teste = Teste + 4
.Cells(Teste, Col).Value = Application.Sum(Range(Cells(c.Row, 3), Cells(c.Row, 14)))
Else
Ligne = .Cells(.Rows.Count, 2).End(xlUp).Offset(1).Row
Range(Cells(c.Row, 1), Cells(c.Row, 2)).Copy .Cells(Ligne, 1)
Rows(Ligne - 1).Copy
Rows(Ligne).PasteSpecial xlPasteFormats
End If
End If
Next c
End With
Wb.Close True
End If
Fich = Dir
Loop
End Sub |
Partager