我正在尝试运行以下VBA代码,并且该代码正在运行。但是在某些情况下结果与预期不符 例如 我有一列值,脚本会查看整个列,选择最小的值并将+1添加到输出中。 但是有时它会跳过此原始列中的一些小值而采用更高的值,而我不明白为什么会这样做
我在此处附加了excel宏工作簿: https://drive.google.com/open?id=1IAHalTjWoTqRT10mgF6bu5l4VB1HgCfv
输出工作表称为:“循环” 可以从工作表“指令”中运行该宏
Option Explicit
Sub Loop_Forecast()
Dim Onglet_Loop As String
Dim First_Ligne, First_Col_Fct, Col_SKU, Col_Inventory, Col_Monthly_Demand, Col_Coverage As Integer
Dim i, Last_ligne, Ligne_Smallest As Long
Dim Qty_Fct_Origin, Qty_Fct_Remain, Compteur, Smallest_Coverage As Variant
'Fige l'écran pendant la suppression des lignes
Application.ScreenUpdating = False
Onglet_Loop = "Loop"
Worksheets(Onglet_Loop).Activate
First_Ligne = 3
Last_ligne = Cells(First_Ligne, 1).End(xlDown).Row
Qty_Fct_Origin = Cells(1, 2).Value
Col_SKU = 1
Col_Inventory = 2
Col_Monthly_Demand = 3
Col_Coverage = 4
First_Col_Fct = 5
Compteur = 0
Do While Compteur < Qty_Fct_Origin
Compteur = Compteur + 1
Smallest_Coverage = Cells(First_Ligne, Col_Coverage).Value
Ligne_Smallest = First_Ligne
For i = First_Ligne + 1 To Last_ligne
If Cells(i, Col_Coverage).Value < Smallest_Coverage Then
Smallest_Coverage = Cells(i, Col_Coverage).Value
Ligne_Smallest = i
End If
Next i
Cells(Ligne_Smallest, First_Col_Fct).Value = Cells(Ligne_Smallest, First_Col_Fct).Value + 1
Loop
'Faire plein de choses qui affectent le contenu des cellules
Application.ScreenUpdating = True
End Sub