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 57 58 59 60 61 62
| Sub Calcul_Book2()
Dim W1 As Worksheet, W2 As Worksheet
Dim DerniereLigne As Long, i As Long, j As Long
Dim Pro As String, Typ As String, Nom As String, Des As String, UniG As String, UniH As String, Uni As String
Dim Nam As String, Nam_Inst As String, Complement As String
Dim MaxG As Double, MinG As Double, MaxH As Double, MinH As Double, Max As Double, Min As Double
' Calcul de Book2, qui est supposé ouvert
Set W1 = Workbooks("test.xlsm").Sheets(1)
Set W2 = Workbooks("Book2.xlsm").Sheets(1)
DerniereLigne = W1.Cells(W1.Rows.Count, 9).End(xlUp).Row
j = 1
For i = 4 To DerniereLigne
Pro = W1.Cells(i, 9)
Typ = W1.Cells(i, 10)
If Typ <> "" And Pro <> "" Then ' Nouvelle ligne compléte
Nom = W1.Cells(i, 1)
Des = W1.Cells(i, 2)
MaxG = W1.Cells(i, 3)
MinG = W1.Cells(i, 4)
UniG = W1.Cells(i, 5)
MaxH = W1.Cells(i, 6)
MinH = W1.Cells(i, 7)
UniH = W1.Cells(i, 8)
Nam = W1.Cells(i - 1, 1)
Nam_Inst = IIf(InStr(Nam, "HK") > 0, Nam & "/", "")
End If
Select Case Pro
Case "g"
Complement = "_x"
Max = MaxG
Min = MinG
Uni = UniG
Case "h"
Complement = "_y"
Max = MaxH
Min = MinH
Uni = UniH
Case "i"
Complement = "_z"
Max = 0
Min = 0
Uni = ""
End Select
If Pro <> "" Then
j = j + 1
W2.Cells(j, 1) = Nom & Complement
W2.Cells(j, 2) = Des & "_" & Pro
W2.Cells(j, 3) = Uni
W2.Cells(j, 4) = Nam_Inst & Nom & ":" & Pro
If Min <> 0 Or Max <> 0 Then
W2.Cells(j, 5) = Max - Min
W2.Cells(j, 6) = (Max + Min) * 0.5
End If
End If
Next i
Set W1 = Nothing
Set W2 = Nothing
End Sub |
Partager