I am trying to build a code that if it finds a specific word in a column it goes to the corresponding column and extracts the data. For some reason my "elseif" for my 3rd loop does not pick up resulting in my code not picking up half the values I need. Can anyone see where I am going wrong?
Sub Summary()
Dim MainLoop As Long
Dim SecondLoop As Long
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 Long
Dim CDesc As String
Dim CPKG As Long
Dim Cstatus As String
MainLoop = 5
SecondLoop = 0
thirdLoop = 0
counter = 0
Worksheets("final").Activate
'1
Do While MainLoop < ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
Worksheets("Final").Activate
ParentSKU = Range("A" & MainLoop).Value
ParentDesc = Range("B" & MainLoop).Value
Worksheets("Summary").Activate
SumRow = (ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row) + 2
Range("A" & SumRow).Value = ParentSKU
Range("B" & SumRow).Value = ParentDesc
Range("C" & SumRow).Value = "Parent"
Worksheets("Final").Activate
SecondLoop = 0
'2
Do While SecondLoop < 20
Worksheets("Final").Activate
'3
If Range("H" & (MainLoop + SecondLoop)).Value = Range("I1").Value Or Range("H" & (MainLoop + SecondLoop)).Value = Range("I2").Value Or Range("H" & (MainLoop + SecondLoop)).Value = Range("I3").Value Then
CSKU = Range("F" & MainLoop + SecondLoop).Value
CDesc = Range("G" & MainLoop + SecondLoop).Value
Cstatus = Range("H" & MainLoop + SecondLoop).Value
CPKG = Range("I" & MainLoop + SecondLoop).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
'3
ElseIf Range("H" & (MainLoop + SecondLoop)).Value = Range("H3").Value Then
Worksheets("Final").Activate
Find = Range("F" & MainLoop + SecondLoop).Value
Trow = 5
'4
Do While Trow < (ActiveSheet.Cells(Rows.Count, "J").End(xlUp).Row) + 1
'5
If Range("J" & Trow).Value = Find Then
thirdLoop = 0
'6
Do While thirdLoop < 10
'7
If Range("P" & Trow + thirdLoop).Value <> "" Or Range("P" & Trow + thirdLoop).Value <> 0 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
'7
Else
Trow = Trow + 1
'7
End If
thirdLoop = thirdLoop + 1
'6
Loop
'5
Else
Trow = Trow + 1
'5
End If
'4
Loop
Else
'3
End If
SecondLoop = SecondLoop + 1
'2
Loop
MainLoop = MainLoop + 20
Worksheets("Final").Activate
'1
Loop
End Sub
Aucun commentaire:
Enregistrer un commentaire