2016-12-06 2 views
0

Ich möchte jede Zeile von NBG_Data Blatt mit jeder Zeile von Comparison_Data Blatt vergleichen, also möchte ich jede Zeile von NBG_Data mit allen Zeilen des Comparison_Data Sheet vergleichen und dann zur nächsten Zeile gehen , bis es die MAX_Row erreicht, das Problem ist, dass ich die For-Schleife nicht verschachteln konnte (was ich wirklich wollte), also probiere ich die Do-Schleife, aber wenn ich den Fehler starte, ist "Loop ohne Do" Wenn jemand bitte sagen mir was ich falsch gemacht habe in der Do-Schleife oder besser modifizieren die für so kann ich eine verschachtelte Arbeit für die Schleife haben.VBA Excel Blätter mit geschachtelt vergleichen Für

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

Schlechte Einrückung macht Code schwerer lesbar, insbesondere Code mit verschachtelten Strukturen. Die 2.x-Pre-Releases von [Rubberduck] (https://github.com/rubberduck-vba/Rubberduck/releases) (ich werde bald eine neue veröffentlichen) beinhalten eine Neufassung des beliebten * Smart Indenters * Add-ons. in, die Ihren Code automatisch, konsistent und schnell für Sie einprägt. –

Antwort

1

Sie haben ein Hybrid zwischen einem Do While...Loop und einer Do...Loop Until Schleife, die VBA nicht weiß, wie zu interpretieren.

Entweder ändern:

Do While Row <= 2 

zu:

Do 

eine gültige Do...Loop Until Schleife zu machen.

Oder Änderung:

Loop Until Row = MAX_Row 

zu:

Loop 

eine gültige Do While...Loop Schleife zu machen.

+0

Vielen Dank –

+0

Sie sind willkommen – user3598756

+0

der Code funktionierte perfekt, aber es gibt ein Problem, jetzt funktioniert die "Next Row" (For-Schleife) nicht, wenn Sie mir bitte helfen können. –

Verwandte Themen