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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
Sub InventorierLesBatchs(ByVal FeuilleMesures As Worksheet, ByVal FeuilleResultats As Worksheet, ByVal Atome As String)
Dim DerniereLigne As Long
Dim CellRecherchee As Range
Dim CelluleEnCours As Range
Dim Cellule As Range
Dim PremiereCelluleTrouvee As Range
Dim AireBatchs As Range
Dim LigneDeTitreFeuilleResultat As Long
Dim ColFeuilleBatch As Long
Dim ColNomDuBatch As Long
Dim ColAtome As Long
Dim ColValeur As Long
Dim LigneResultatBatch As Long
Dim Continuer As Boolean
LigneDeTitreFeuilleResultat = 10
LigneResultatBatch = LigneDeTitreFeuilleResultat + 1
ColFeuilleBatch = 1
ColNomDuBatch = 2
ColAtome = 3
ColValeur = 4
' Effacement de la feuille résultats
'-----------------------------------
With FeuilleResultats
.Range(.Cells(LigneResultatBatch, 1), .Cells(.Rows.Count, .Columns.Count)).ClearContents
End With
With FeuilleMesures
Continuer = True
Set CelluleEnCours = .Cells(1, 2)
Set PremiereCelluleTrouvee = .Cells.Find(What:="batch", After:=CelluleEnCours, LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Not PremiereCelluleTrouvee Is Nothing Then
Set CelluleEnCours = PremiereCelluleTrouvee
Else
Continuer = False
End If
Do While Continuer = True
Set CellRecherchee = .Cells.Find(What:="batch", After:=CelluleEnCours, LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Not CellRecherchee Is Nothing Then
' Le programme est interrompu si le premier batch est de nouveau trouvé.
If CellRecherchee = PremiereCelluleTrouvee Then
Continuer = False
End If
Set CelluleEnCours = CellRecherchee
With FeuilleResultats
.Cells(LigneResultatBatch, ColFeuilleBatch) = FeuilleMesures.Name
.Cells(LigneResultatBatch, ColNomDuBatch) = CellRecherchee
.Cells(LigneResultatBatch, ColAtome) = .Range("AtomeARecuperer")
LigneResultatBatch = LigneResultatBatch + 1
End With
End If
Set CellRecherchee = Nothing
Loop
Set CelluleEnCours = Nothing
Set PremiereCelluleTrouvee = Nothing
End With
' Mise en place de la formule ResultatBatchV2
With FeuilleResultats
DerniereLigne = .Cells(.Rows.Count, ColFeuilleBatch).End(xlUp).Row
If DerniereLigne > LigneDeTitreFeuilleResultat Then
Set AireBatchs = .Range(.Cells(LigneDeTitreFeuilleResultat + 1, ColValeur), .Cells(DerniereLigne, ColValeur))
For Each Cellule In AireBatchs
With Cellule
.FormulaR1C1 = "=ResultatBatchV2(RC[-3],RC[-2],RC[-1])"
.NumberFormat = "0.00"
.HorizontalAlignment = xlCenter
End With
Next Cellule
Set AireBatchs = Nothing
End If
' Tri des batchs
Set AireBatchs = .Range(.Cells(LigneDeTitreFeuilleResultat, 1), .Cells(DerniereLigne, ColValeur))
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range(.Cells(LigneDeTitreFeuilleResultat + 1, ColNomDuBatch), .Cells(DerniereLigne, ColNomDuBatch)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.SetRange AireBatchs
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Set AireBatchs = Nothing
End With
Set FeuilleMesures = Nothing
End Sub |
Partager