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
| Option Explicit
Sub ListerES()
Dim D As Date, D1 As Date, D2 As Date, mD As String
Dim wSh1 As Worksheet, wSh2 As Worksheet
Dim kR1 As Long, kR2 As Long
Dim kS As Long, kE As Long
If Cells(2, 1) & Cells(2, 4) <> "" Then
MsgBox "Commencer par vider cette feuille de ses données !", _
vbExclamation, "Opération annulée"
Exit Sub
End If
Set wSh1 = Worksheets("Feuil1")
Set wSh2 = Worksheets("Feuil2")
kR1 = 4 '--- n° première ligne feuille 1
kR2 = 2 '--- n° première ligne feuille 2
wSh2.Select
D1 = Range("H1") '--- date1
D2 = Range("J1") '--- date2
With wSh1
While .Cells(kR1, 9) <> ""
D = .Cells(kR1, 9)
If D >= D1 And D <= D2 Then
mD = .Cells(kR1, 10) '--- mouvement à la date D
kS = InStr(mD, "(SORTIE")
kE = InStr(mD, "(ENTREE")
If kS > 0 Then
Cells(kR2, 2) = Mid(mD, kS + 8, Len(mD) - kS - 8)
Cells(kR2, 3) = D
'--- extraire référence Sortie
mD = Replace(mD, "NC ", "") '--- retire le NC éventuel
Cells(kR2, 1) = Val(mD) '--- prend le nombre
kR2 = kR2 + 1
ElseIf kE > 0 Then
Cells(kR2, 5) = Mid(mD, kE + 8, Len(mD) - kE - 8)
Cells(kR2, 6) = D
'--- extraire référence Entrée
kE = InStr(mD, "/") '--- suppose qu'il y a TOUJOURS une / dans la référence
mD = Mid(mD, kE - 2)
Cells(kR2, 4) = Left(mD, InStr(mD, " ") - 1)
kR2 = kR2 + 1
Else
MsgBox "Ni SORTIE ni ENTREE en ligne " & kR1, _
vbExclamation, "Anomalie"
End If
End If
kR1 = kR1 + 1
Wend
End With
Set wSh1 = Nothing
Set wSh2 = Nothing
End Sub |
Partager