因此,我在下面的代码尝试在H列中找到WIP。如果我们找到WIP:复制3个单元格并在下一列中将它们分别放在同一行或下一个可用行中。
由于某种原因,代码只为第一个" WIP"成功运行循环。值然后停止运行。有人能看出为什么会这样吗?
谢谢你, Ori
Sub Step1_update()
Dim dblSKU As Double
Dim strDesc As String
Dim strType As String
Dim BrowFin As Integer
Dim Browfin1 As Integer
Dim Counter As Integer
Dim Trowfin As Integer
Counter = 0
Worksheets("Final").Activate
Trowfin = 5
BrowFin = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
'loop 1
Do While Trowfin < BrowFin
'If 1
If Range("H" & Trowfin).Value = Range("H3").Value Then
dblSKU = Range("F" & Trowfin).Value
strDesc = Range("G" & Trowfin).Value
strType = Range("H" & Trowfin).Value
Browfin1 = (ActiveSheet.Range("J" & Rows.Count).End(xlUp).Row)
'If 2
If Browfin1 > Trowfin Then
Do While Counter < 15
Range("J" & Browfin1).Value = dblSKU
Range("K" & Browfin1).Value = strDesc
Range("L" & Browfin1).Value = strType
Counter = Counter + 1
Browfin1 = Browfin1 - 1
Trowfin = Trowfin + 1
Loop
ElseIf Browfin1 < Trowfin Then
Do While Counter < 15
Range("J" & Trowfin).Value = dblSKU
Range("K" & Trowfin).Value = strDesc
Range("L" & Trowfin).Value = strType
Counter = Counter + 1
Trowfin = Trowfin + 1
Loop
Else
Do While Counter < 15
Range("J" & Trowfin).Value = dblSKU
Range("K" & Trowfin).Value = strDesc
Range("L" & Trowfin).Value = strType
Counter = Counter + 1
Trowfin = Trowfin + 1
Loop
'If 2
End If
Else
Trowfin = Trowfin + 1
'If 1
End If
counter = 0
'loop 1
Loop
End Sub
答案 0 :(得分:0)
您可能需要在循环后将计数器重置为0。否则,下次再次进入循环时,您已经在15岁了。