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
| Sub test()
Dim C As Range, Tabl, Mois As String, Ligne As Long, Col As Integer
With Sheets("base A HOTEL")
Tabl = .Range(.[C5], .Cells(.Rows.Count, 3).End(xlUp)).Resize(, 6)
End With
With Sheets("A HOTEL")
For i = 1 To UBound(Tabl)
If Tabl(i, 1) = "" And Tabl(i, 2) <> "" Then
Tabl(i, 1) = Tabl(i - 1, 1)
End If
Mois = UCase(Format(Tabl(i, 2), "mmm"))
If Tabl(i, 1) <> "" Then
If Not IsNumeric(Application.Match(Tabl(i, 1), .[A:A], 0)) Then
MsgBox "Compte " & Tabl(i, 1) & " non présent"
Else
Ligne = Application.Match(Tabl(i, 1), .[A:A], 0)
Col = Application.Match(Mois, .Rows(3), 0)
' If Application.CountA(.Range(.[C5], .Cells(.Rows.Count, 3).End(xlUp))) > 0 Then
' .Range(.Cells(4, Col), .Cells(.Rows.Count, Col).End(xlUp)).ClearContents
' End If
If Left(Tabl(i, 1), 1) = "7" Then
If Tabl(i, 5) <> "" Then Tabl(i, 5) = Tabl(i, 5) * -1
If Tabl(i, 6) <> "" Then Tabl(i, 6) = Tabl(i, 6) * -1
End If
If Tabl(i, 5) <> "" Then .Cells(Ligne, Col).Value = .Cells(Ligne, Col).Value + Tabl(i, 5)
If Tabl(i, 6) <> "" Then .Cells(Ligne, Col).Value = .Cells(Ligne, Col).Value - Tabl(i, 6)
End If
End If
Next i
End With
End Sub |
Partager