Makro erweitern

  • Excel

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von salva.

    Makro erweitern

    Hallo Experten,

    ich sitzte sehr lange vor einem Problem und kann es nicht lösen. Ich bin völlig unerfahren in VBA und bräuchte bitte Eure Hilfe.

    Es geht um folgendes Makro:

    Visual Basic-Quellcode

    1. Public Sub Tabelle1Auswertung()
    2. Dim arrY As Variant, arrG As Variant, arrR As Variant
    3. Dim r As Long, y As Integer, g As Integer, reslt As Integer
    4. '***ScreenUpdating
    5. Application.ScreenUpdating = False
    6. Application.Calculation = xlCalculationManual
    7. '***Auswertung durchführen
    8. With Worksheets("Tabelle1")
    9. For r = 3 To 9
    10. '***Einlesen Zeile
    11. arrY = .Cells(r, "H").Resize(1, 6)
    12. arrG = .Cells(r, "P").Resize(1, 3)
    13. arrR = .Cells(r, "V").Resize(1, 3)
    14. '***Auswerten "Anzahl Fehler" Yellow
    15. reslt = 0
    16. For y = 1 To UBound(arrY, 2) Step 2
    17. If arrY(1, y) > 0 Or arrY(1, y + 1) > 0 Then reslt = reslt + 1
    18. Next y
    19. .Cells(r, "G") = reslt
    20. '***Auswerten "Anzahl Fehler" Green
    21. reslt = 0
    22. For g = 1 To UBound(arrG, 2)
    23. If arrG(1, g) > 0 Then reslt = reslt + 1
    24. Next g
    25. .Cells(r, "O") = reslt
    26. '***Auswerten "Anzahl richtig"
    27. reslt = 0
    28. For g = 1 To UBound(arrG, 2)
    29. If arrG(1, g) <> 0 And Not IsEmpty(arrG(1, g)) Then
    30. For y = 1 To UBound(arrY, 2) Step 2
    31. If arrG(1, g) >= arrY(1, y) And arrG(1, g) <= arrY(1, y + 1) Then
    32. reslt = reslt + 1
    33. arrY(1, y) = Empty: arrY(1, y + 1) = Empty
    34. arrG(1, g) = Empty
    35. Exit For
    36. End If
    37. Next y
    38. End If
    39. Next g
    40. .Cells(r, "D") = IIf(reslt > 0, reslt, "")
    41. '***Auswerten "Anzahl Schlupf"
    42. reslt = 0
    43. For g = 1 To UBound(arrG, 2)
    44. If arrG(1, g) <> 0 And Not IsEmpty(arrG(1, g)) Then
    45. reslt = reslt + 1
    46. arrG(1, g) = Empty
    47. End If
    48. Next g
    49. .Cells(r, "E") = IIf(reslt > 0, reslt, "")
    50. '***Auswerten "Anzahl Pseudo"
    51. reslt = 0
    52. For y = 1 To UBound(arrY, 2) Step 2
    53. If arrY(1, y) <> 0 And Not IsEmpty(arrY(1, y)) And _
    54. arrY(1, y + 1) <> 0 And Not IsEmpty(arrY(1, y + 1)) Then
    55. reslt = reslt + 1
    56. arrY(1, y) = Empty: arrY(1, y + 1) = Empty
    57. End If
    58. Next y
    59. .Cells(r, "F") = IIf(reslt > 0, reslt, "")
    60. '***Auswerten "Gesamtentscheid"
    61. .Cells(r, "B") = IIf(.Cells(r, "E") + .Cells(r, "F") > 0, 0, 1)
    62. Next r
    63. End With
    64. '***ScreenUpdating
    65. Application.ScreenUpdating = True
    66. Application.Calculation = xlCalculationAutomatic
    67. End Sub


    Die Auswertung soll nun die letzten 3 Spalten V-X (siehe Anhang), in denen die Größe der Fehler in den grünhinterlegten Spalten drinstehen, berücksichtigen. Immer wenn die Größe der Fehler kleiner 2 ist (z.B. 0,8 und 1) und nicht in H-M gefunden werden, dann soll dies nicht als Schlupf gewertet werden und somit auch nicht den Gesamtentscheid beeinflussen (z.B. wären das die Fehler R5 und P7).

    Als Erstes habe ich am Anfang ein neues array deklariert und es "arrR" genannt, wegen den rothinterlegten Spalten V-X. Danach habe ich in Abschnitt '***Einlesen Zeile dieses Array entsprechend hinzugefügt.
    Ich bin mir allerdings nicht sicher, ob ich für diese Erweiterung ein neues Array überhaupt brauche?

    Als Nächstes habe ich in dem Abschnitt '***Auswerten "Anzahl Schlupt" vieles ausprobiert und nichts klappt (u.a. habe ich es mit einer Elseif-Schleife erfolglos probiert).

    Die Excel Tabelle zusammen mit dem Makro schicke ich Euch als Anhang.

    Ich hoffe Ihr könnt mir weiterhelfen.

    Danke!

    Gruß salva
    Dateien
    • Test.xls

      (46,08 kB, 175 mal heruntergeladen, zuletzt: )
    Hallo,

    ich glaub, ich habe es geschafft!

    Hoffe es funktioniert! Muss es nur noch ausgiebig testen.

    Hab dafür den Code folgendermaßen erweitert:

    Quellcode

    1. Public Sub Tabelle1Auswertung()
    2. Dim arrY As Variant, arrG As Variant, arrR As Variant
    3. Dim r As Long, y As Integer, g As Integer, reslt As Integer
    4. '***ScreenUpdating
    5. Application.ScreenUpdating = False
    6. Application.Calculation = xlCalculationManual
    7. '***Auswertung durchführen
    8. With Worksheets("Tabelle1")
    9. For r = 3 To 9 '.Range("H" & Rows.Count).End(xlUp).Row
    10. '***Einlesen Zeile
    11. arrY = .Cells(r, "H").Resize(1, 6)
    12. arrG = .Cells(r, "P").Resize(1, 3)
    13. arrR = .Cells(r, "V").Resize(1, 3)
    14. '***Auswerten "Anzahl Fehler" Yellow
    15. reslt = 0
    16. For y = 1 To UBound(arrY, 2) Step 2
    17. If arrY(1, y) > 0 Or arrY(1, y + 1) > 0 Then reslt = reslt + 1
    18. Next y
    19. .Cells(r, "G") = reslt
    20. '***Auswerten "Anzahl Fehler" Green
    21. reslt = 0
    22. For g = 1 To UBound(arrG, 2)
    23. If arrG(1, g) > 0 Then reslt = reslt + 1
    24. Next g
    25. .Cells(r, "O") = reslt
    26. '***Auswerten "Anzahl richtig"
    27. reslt = 0
    28. For g = 1 To UBound(arrG, 2)
    29. If arrG(1, g) <> 0 And Not IsEmpty(arrG(1, g)) Then
    30. For y = 1 To UBound(arrY, 2) Step 2
    31. If arrG(1, g) >= arrY(1, y) And arrG(1, g) <arrY> 0, reslt, "")
    32. '***Auswerten "Anzahl Schlupf"
    33. reslt = 0
    34. For g = 1 To UBound(arrG, 2)
    35. If arrG(1, g) <> 0 And Not IsEmpty(arrG(1, g)) And arrR(1, g) > 2 Then
    36. reslt = reslt + 1
    37. arrG(1, g) = Empty
    38. End If
    39. Next g
    40. .Cells(r, "E") = IIf(reslt > 0, reslt, "")
    41. '***Auswerten "Anzahl Pseudo"
    42. reslt = 0
    43. For y = 1 To UBound(arrY, 2) Step 2
    44. If arrY(1, y) <> 0 And Not IsEmpty(arrY(1, y)) And _
    45. arrY(1, y + 1) <> 0 And Not IsEmpty(arrY(1, y + 1)) Then
    46. reslt = reslt + 1
    47. arrY(1, y) = Empty: arrY(1, y + 1) = Empty
    48. End If
    49. Next y
    50. .Cells(r, "F") = IIf(reslt > 0, reslt, "")
    51. '***Auswerten "Gesamtentscheid"
    52. .Cells(r, "B") = IIf(.Cells(r, "E") + .Cells(r, "F") > 0, 0, 1)
    53. Next r
    54. End With
    55. '***ScreenUpdating
    56. Application.ScreenUpdating = True
    57. Application.Calculation = xlCalculationAutomatic
    58. End Sub


    Ich habe einfach ein neues array deklariert und im Abschnitt '***Auswerten "Anzahl Schlupf" die Erweiterung And arrR(1, g) > 2 hinzugefügt. :)

    Gruß salva