Вложенные циклы & Ifs, цикл без Do
Я продолжаю получать цикл без Do каждый раз, когда запускаю свой код, и я не вижу, где я что-то упускаю или неуместен ли цикл. Мне нужен этот код, чтобы найти ключевые слова в определенных столбцах, скопировать и вставить их в сводную вкладку.
Ваша помощь будет принята с благодарностью.
Sub Summary()
Dim MainLoop As Double
Dim SecondLoop As Double
Dim thirdLoop As Double
Dim Trow As Double
Dim counter As Integer
Dim PSKU As Integer
Dim PDesc As String
Dim PPKG As Integer
Dim CSKU As Integer
Dim CDesc As String
Dim CPKG As Integer
Dim Cstatus As String
MainLoop = 5
SecondLoop = 0
thirdLoop = 0
Trow = 5
counter = 0
Worksheets("final").Activate
Do While MainLoop < ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
Worksheets("Final").Activate
ParentSKU = Range("F" & MainLoop).Value
ParentDesc = Range("G" & MainLoop).Value
Worksheets("Summary").Activate
SumRow = (ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row) + 1
Range("A" & SumRow).Value = ParentSKU
Range("B" & SumRow).Value = ParentDesc
Range("C" & SumRow).Value = "Parent"
Worksheets("Final").Activate
Do While SecondLoop < 20
If Range("H" & MainLoop + SecondLoop).Value = "MAT" Or "PKG" Or "ING" Then
Range("F" & MainLoop + SecondLoop).Value = CSKU
Range("G" & MainLoop + SecondLoop).Value = CDesc
Range("H" & MainLoop + SecondLoop).Value = (Cstatus)
Range("I" & MainLoop + SecondLoop).Value = CPKG
Worksheets("Summary").Activate
SumRow = (ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row) + 1
Range("A" & SumRow).Value = CSKU
Range("B" & SumRow).Value = CDesc
Range("C" & SumRow).Value = "Child"
Range("D" & SumRow).Value = CPKG
ElseIf Range("H" & MainLoop + SecondLoop).Value = "WIP" Then
Find = Range("F" & MainLoop + SecondLoop).Value
Do While Trow < ActiveSheet.Cells(Rows.Count, "J").End(xlUp).Row & thirdLoop < 20
If Range("J" & Trow).Value = Find Then
If Range("P" & Trow + thirdLoop).Value <> "" Then
CSKU = Range("P" & Trow + thirdLoop).Value
CDesc = Range("Q" & Trow + thirdLoop).Value
Cstatus = Range("R" & Trow + thirdLoop).Value
CPKG = Range("S" & Trow + thirdLoop).Value
Worksheets("Summary").Activate
SumRow = (ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row) + 1
Range("A" & SumRow).Value = CSKU
Range("B" & SumRow).Value = CDesc
Range("C" & SumRow).Value = "Child"
Range("D" & SumRow).Value = CPKG
Worksheets("Final").Activate
thirdLoop = thirdLoop + 1
Trow = Trow + 1
Else
Trow = Trow + 1
End If
Else
thirdLoop = thirdLoop + 1
End If
Loop
End If
SecondLoop = SecondLoop + 1
MainLoop = MainLoop + 20
Loop
Worksheets("Final").Activate
End Sub
1 ответ
В следующем разделе отсутствует End If
If Range("P" & Trow + thirdLoop).Value <> "" Then
CSKU = Range("P" & Trow + thirdLoop).Value
CDesc = Range("Q" & Trow + thirdLoop).Value
Cstatus = Range("R" & Trow + thirdLoop).Value
CPKG = Range("S" & Trow + thirdLoop).Value
Worksheets("Summary").Activate
SumRow = (ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row) + 1
Range("A" & SumRow).Value = CSKU
Range("B" & SumRow).Value = CDesc
Range("C" & SumRow).Value = "Child"
Range("D" & SumRow).Value = CPKG
Worksheets("Final").Activate
thirdLoop = thirdLoop + 1
Trow = Trow + 1
'missing end if here
Loop