0

I want to compare every row of NBG_Data sheet with every row of Comparison_Data sheet , so i want each row of NBG_Data to be compared with all the rows of the Comparison_Data Sheet then go to the next row , till it reaches the MAX_Row ,the issue is that i couldn't Nest the For loop (which i really wanted) so i am trying the Do loop , but when i start the error is "Loop without Do" If anyone please tell me what I did wrong in the Do loop or better modify the for so i can have a nested working for loop .

For Row = 2 To MAX_Row


CompMonth = Worksheets(NBG_ComparisonDataWorksheetName).Cells(Row, SOP).Value
CompMonth = DatePart("m", CompMonth)

CompYear = Worksheets(NBG_ComparisonDataWorksheetName).Cells(Row, SOP).Value
CompYear = DatePart("yyyy", CompYear)


CompCarmaker = Worksheets(NBG_ComparisonDataWorksheetName).Cells(Row, Carmaker).Value
CompProject = Worksheets(NBG_ComparisonDataWorksheetName).Cells(Row, Project).Value
CompFamily = Worksheets(NBG_ComparisonDataWorksheetName).Cells(Row, Family).Value
CompStatus = Worksheets(NBG_ComparisonDataWorksheetName).Cells(Row, Status).Value
CompShare = Worksheets(NBG_ComparisonDataWorksheetName).Cells(Row, Share).Value


Do While Row <= 2

NBGMonth = Worksheets(NBG_DataWorksheetName).Cells(Row, SOP).Value
NBGMonth = DatePart("m", NBGMonth)

NBGYear = Worksheets(NBG_DataWorksheetName).Cells(Row, SOP).Value
NBGYear = DatePart("yyyy", NBGYear)

NBGCarmaker = Worksheets(NBG_DataWorksheetName).Cells(Row, Carmaker).Value
NBGProject = Worksheets(NBG_DataWorksheetName).Cells(Row, Project).Value
NBGFamily = Worksheets(NBG_DataWorksheetName).Cells(Row, Family).Value
NBGStatus = Worksheets(NBG_DataWorksheetName).Cells(Row, Status).Value
NBGShare = Worksheets(NBG_DataWorksheetName).Cells(Row, Share).Value

Row = Row + 1


 ' StatusBar Show

 Application.StatusBar = "VerifySumofShares. Progress: " & Row & " of " & MAX_Row


        If (NBGMonth = CompMonth And NBGYear = CompYear And CompCarmaker = NBGCarmaker And CompProject = NBGProject And CompFamily = NBGFamily And NBGStatus <> "LOST" And CompStatus <> "LOST" And CompShare + NBGShare <= 99 And CompShare + NBGShare > 100) Then



            Worksheets(Issue_SumofSharesWorksheetName).Cells(3 + Issue_SumofSharesCnt, "A").Value = Row
            Worksheets(Issue_SumofSharesWorksheetName).Cells(3 + Issue_SumofSharesCnt, "B").Value = Worksheets(NBG_RegionaDataWorksheetName).Cells(Row, Project).Value
            Worksheets(Issue_SumofSharesWorksheetName).Cells(3 + Issue_SumofSharesCnt, "C").Value = GetMonthAndQuarter(Worksheets(NBG_RegionaDataWorksheetName).Cells(Row, SOP).Value)
            Worksheets(Issue_SumofSharesWorksheetName).Cells(3 + Issue_SumofSharesCnt, "D").Value = Worksheets(NBG_RegionaDataWorksheetName).Cells(Row, Family).Value
            Worksheets(Issue_SumofSharesWorksheetName).Cells(3 + Issue_SumofSharesCnt, "E").Value = Worksheets(NBG_RegionaDataWorksheetName).Cells(Row, Responsible).Value

           ' Region As String
            Region = ""

            'Add any other GeoRegion which is also responsible in the recorded data


            If Worksheets(NBG_DataWorksheetName).Cells(Row, "BC") Then
            Region = Region + "@EMEA"
            End If

            If Worksheets(NBG_DataWorksheetName).Cells(Row, "BD") Then
            Region = Region + "@AMERICAS"
            End If

            If Worksheets(NBG_DataWorksheetName).Cells(Row, "BE") Then
            Region = Region + "@GCSA"
            End If

            If Worksheets(NBG_DataWorksheetName).Cells(Row, "BF") Then
            Region = Region + "@JAPAN&KOREA"
            End If


            Worksheets(Issue_SumofSharesWorksheetName).Cells(3 + Issue_SumofSharesCnt, "F").Value = Region

            'Count the number of the cases recorded


            Issue_SumofSharesCnt = Issue_SumofSharesCnt + 1

            'If there is no items , the Message to show


        ElseIf (Worksheets(NBG_RegionaDataWorksheetName).Cells(Row, SOP).Value = "There are no items to show in this view.") Then


    End If

     Loop Until Row = MAX_Row

Next Row
0

1 Answer 1

1

You have a hybrid between a Do While...Loop and a Do...Loop Until loop, which VBA doesn't know how to interpret.

Either change:

    Do While Row <= 2

to:

    Do

to make a valid Do...Loop Until loop.

Or change:

    Loop Until Row = MAX_Row

to:

    Loop

to make a valid Do While...Loop loop.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much
the code worked perfectly but athere is a problem , now the "Next Row" (For loop) does not work , if you please can help me .
You can't update the current outer For- Next loop iterator (Row) inside the loop itself (you have that Row = Row + 1 inside the inner Do While Row <= 2 loop). You might want to turn the outer For Row = 2 To MAX_Row - Next Row loop into a Do - While Row <= MAX_Row one
Okay , Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.