Thema Datum  Von Nutzer Rating
Antwort
18.01.2020 18:42:14 Jana
NotSolved
18.01.2020 19:20:07 Mase
NotSolved
25.01.2020 19:07:52 Jana
NotSolved
25.01.2020 19:16:19 Mase
NotSolved
25.01.2020 19:49:53 Jana
NotSolved
25.01.2020 20:08:38 Mase
NotSolved
26.01.2020 13:52:16 Jana
NotSolved
19.01.2020 15:42:40 Jana
NotSolved
Rot Verschachtelte Schleifen
26.01.2020 12:46:15 Gast52795
*****
Solved
26.01.2020 12:58:20 Gast81966
Solved
26.01.2020 14:10:51 Jana
NotSolved
26.01.2020 16:48:44 Gast8113
NotSolved

Ansicht des Beitrags:
Von:
Gast52795
Datum:
26.01.2020 12:46:15
Views:
769
Rating: Antwort:
 Nein
Thema:
Verschachtelte Schleifen

Würde ich in seine Teilprobleme zerlegen.

* Dummy_Aufruf kümmert sich um das Löschen des importierten Blatts, falls ein Abgleich möglich war

* WksMatch führt den Abgleich durch (Datenzeile 5 kopieren)

* WksCompare führt den Vergleich / die Suche nach dem richtigen Blatt durch

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Option Explicit
 
Sub Dummy_Aufruf()
   
  Dim wks As Excel.Worksheet
   
  If WksMatch(ActiveSheet, ActiveWorkbook, wks) Then
'    Application.DisplayAlerts = False
    ActiveSheet.Delete
'    Application.DisplayAlerts = True
'    wks.Activate
  End If
   
End Sub
 
Function WksMatch(Optional ByVal Source As Excel.Worksheet, Optional ByVal CompareWith As Excel.Workbook, Optional ByRef Match As Excel.Worksheet) As Boolean
   
  If Source Is Nothing Then Set Source = ActiveSheet 'gehe hier einfachhalber davon aus, dass ActiveSheet ein Tabellenblatt ist
  If CompareWith Is Nothing Then Set CompareWith = ActiveWorkbook
   
  Dim wks As Excel.Worksheet
  Dim i As Long
   
  For Each wks In CompareWith.Worksheets
    If Not wks Is Source Then
      If WksCompare(Source, wks, 1) Then
'        Debug.Print "'"; Source.Name; "' equal to '"; wks.Name; "'"
        Source.Rows(5).Copy wks.Cells(wks.Rows.Count, "A").End(xlUp).Offset(1) 'unter die letzte Zeile kopieren; über Spalte A ermittelt
        Set Match = wks
        WksMatch = True
        Exit Function
      End If
    End If
  Next
   
End Function
 
Private Function WksCompare(ByVal Worksheet1 As Excel.Worksheet, ByVal Worksheet2 As Excel.Worksheet, ByVal Row As Long) As Boolean
 
  Dim c As Variant
   
  ' c() = {COLUMN_MAX, COLUMN_MAX_WKS1,COLUMN_MAX_WKS2}
  c = Array(0, Worksheet1.Cells(Row, Worksheet1.Columns.Count).End(xlToLeft).Column, _
              Worksheet2.Cells(Row, Worksheet2.Columns.Count).End(xlToLeft).Column)
  c(0) = WorksheetFunction.Max(c(1), c(2))
   
  'wenn sich die Spalten-Anzahl beider Tabellen unterscheidet,
  'kann man hier theoretisch/faktisch bereits aufhören - keine Übereinstimmung mgl.
  If c(1) <> c(2) Then Exit Function
   
  Dim i As Long
   
  For i = 1 To c(0)
    If Worksheet1.Cells(Row, c(1)).Value <> Worksheet2.Cells(Row, c(2)).Value Then
      Exit Function
    End If
  Next
   
  WksCompare = True
   
End Function

 

LG


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
18.01.2020 18:42:14 Jana
NotSolved
18.01.2020 19:20:07 Mase
NotSolved
25.01.2020 19:07:52 Jana
NotSolved
25.01.2020 19:16:19 Mase
NotSolved
25.01.2020 19:49:53 Jana
NotSolved
25.01.2020 20:08:38 Mase
NotSolved
26.01.2020 13:52:16 Jana
NotSolved
19.01.2020 15:42:40 Jana
NotSolved
Rot Verschachtelte Schleifen
26.01.2020 12:46:15 Gast52795
*****
Solved
26.01.2020 12:58:20 Gast81966
Solved
26.01.2020 14:10:51 Jana
NotSolved
26.01.2020 16:48:44 Gast8113
NotSolved