VBA vergleich 2 Excel Frage

  • Excel

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

    VBA vergleich 2 Excel Frage

    Hallo,

    ich bin neu hier und mein erster Beitrag fangt mit Frage :D .
    Ich bin auch neu bei VBA Excel Programmierung.


    Ich muss 2 Excel vergleichen " Zeile : Name: nicht geändert, Neu oder Gelöscht ; Spalte : wenn in der Zeile nicht geändert wurde dann Spalte vergleichen ob was geändert wurde " und Diff speichern und markieren . soweit habe ich kein Problem.
    Mein Problem ist
    im Excel sind gleiche Name ca 6 vorhanden und manchmal kann vorkommen dass die Name gelöscht ist , oder im Excel 2 neu dazu gekommen
    Bp.
    Excel 1
    Muller 1985 180cm Blond ....... A1
    Muller 1600€ 30T unbef ..... A2
    Muller ......... A3
    Muller ........ A4

    Excel 2
    Muller 1985 180cm Blond ....... A1
    Muller 1800€ 30T unbef ..... A2
    Muller ......... A3
    Muller ........ A4

    Excel 1
    Ralf ...........A25-A30
    Marc ..........A31-A35
    Exce2
    Marc .........A25-A30

    Soll
    Muller A2 im B2 wurde geändert
    Ralf ist gelöscht
    dann soll Marc "Excel1" A31-35 mit Marc "Excel2" A25-A30 vergleichen



    Es geht wenn nur einmal Muller vorhanden ist

    Für eure Vorschläge bin ich bedankbar

    Visual Basic-Quellcode

    1. Sub DiffTM()
    2. Dim l(200) As Boolean
    3. Dim idiff As Boolean
    4. Zeile_Old = Workbooks(sFILETM2).Sheets(1).UsedRange.Rows.Count
    5. Spalte_Old = Workbooks(sFILETM2).Sheets(1).UsedRange.Columns.Count
    6. Zeile_New = Workbooks(sFILETM).Sheets(1).UsedRange.Rows.Count
    7. Spalte_New = Workbooks(sFILETM).Sheets(1).UsedRange.Columns.Count
    8. Tabell1 = Workbooks(sFILETM2).Sheets(1).Name
    9. Tabell1 = Workbooks(sFILETM).Sheets(1).Name
    10. 'Tabell2 = Workbooks(sFILETM2).Sheets(2).Name
    11. 'Tabell2 = Workbooks(sFILETM).Sheets(2).Name
    12. If Sheets("CTRL").OptionButtonIN.Value = "Wahr" Then
    13. sSection = Tabell1
    14. Sheets("DIFF_1").Activate
    15. Else
    16. sSection = Tabell2
    17. Sheets("DIFF_2").Activate
    18. End If
    19. ActiveSheet.Range("A5:O65536").Select
    20. Selection.Interior.ColorIndex = 0
    21. Selection = ""
    22. ActiveSheet.Range("A1:A1").Select
    23. ZMAX = Workbooks(sFILETM).Sheets(sSection).UsedRange.Rows.Count
    24. SMAX = Workbooks(sFILETM).Sheets(sSection).UsedRange.Columns.Count
    25. Z2MAX = Workbooks(sFILETM2).Sheets(sSection).UsedRange.Rows.Count
    26. Spalte = Workbooks(sFILETM2).Sheets(sSection).UsedRange.Columns.Count
    27. IMAX = Z2MAX
    28. JMAX = ZMAX
    29. PMAX = JMAX * 2
    30. K = 5
    31. For I = 2 To IMAX
    32. For J = 2 To JMAX
    33. If Workbooks(sFILETM2).Sheets(sSection).Cells(I, 1) = Workbooks(sFILETM).Sheets(sSection).Cells(J, 1) Then
    34. idiff = False
    35. For a = 1 To Spalte
    36. l(a) = (Workbooks(sFILETM).Sheets(sSection).Cells(J, a) <> Workbooks(sFILETM2).Sheets(sSection).Cells(I, a))
    37. If l(a) Then idiff = True
    38. Next a
    39. If idiff = True Then
    40. For M = 1 To a
    41. Cells(K, M) = Workbooks(sFILETM2).Sheets(sSection).Cells(I, M)
    42. If l(M) Then
    43. Cells(K, M) = Workbooks(sFILETM2).Sheets(sSection).Cells(I, M)
    44. Call DoBlue(K, M)
    45. End If
    46. Next M
    47. K = K + 1
    48. End If
    49. Exit For
    50. Else
    51. If J = JMAX Then
    52. For M = 1 To a
    53. Cells(K, M) = Workbooks(sFILETM2).Sheets(sSection).Cells(I, M)
    54. Call DoGreen(K, M)
    55. Next M
    56. K = K + 1
    57. End If
    58. End If
    59. Next J
    60. Next I
    61. For I = 2 To IMAX
    62. For J = 2 To JMAX
    63. If Workbooks(sFILETM2).Sheets(sSection).Cells(J, 1) = Workbooks(sFILETM).Sheets(sSection).Cells(I, 1) Then
    64. Exit For
    65. Else
    66. If J = JMAX Then
    67. For M = 1 To a
    68. Cells(K, M) = Workbooks(sFILETM).Sheets(sSection).Cells(I, M)
    69. Call DoRed(K, M)
    70. Next M
    71. K = K + 1
    72. End If
    73. End If
    74. Next J
    75. Next I
    76. Workbooks(sFILETM).Close
    77. Workbooks(sFILETM2).Close
    78. End Sub


    *Topic verschoben*

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Marcus Gräfe“ ()