Live-Forum - Die aktuellen Beiträge
Datum
Titel
24.04.2024 19:29:30
24.04.2024 18:49:56
24.04.2024 17:19:09
Anzeige
Archiv - Navigation
528to532
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
528to532
528to532
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Copy Befehl wird ignoriert

Copy Befehl wird ignoriert
06.12.2004 20:19:18
Thomas
Hallo Forum und Hilfesuchende
Hier etwas, um sich an den Kopf zu schlagen:
Das folgende Gerüsst hab ich mir aus der Recherche zusammengesucht.
Es funktioniert auch, bis auf den Copy Befehl, etwa in der Mitte.
(Weiter, siehe etwa in der Mitte)

Private Sub Workbook_Open()
Worksheets("Tabelle1").Activate
Dim neuDatum As String
Dim neuPrüfen As VbMsgBoxResult
Do
neuDatum = InputBox("Datum einfügen TT-MM-JJ")
If neuDatum = Empty Then
neuPrüfen = MsgBox("Die Datei wird ohne Anschließendes speichern geöffnet!", vbOKOnly)
Exit Sub
End If
If IsDate(neuDatum) Then Exit Do Else
neuPrüfen = MsgBox("Falsches Format oder ungültiges Datum! Erneute Eingabe?", vbYesNo)
If neuPrüfen = vbNo Then
ActiveWorkbook.Close SaveChanges:=True
Else
End If
Loop
Range("N2").Select
Selection.Range("N2").Insert
ActiveCell.FormulaR1C1 = neuDatum
ActiveWorkbook.SaveAs neuDatum
'Zwei Zeilen weiter steht der Copy Befehl, der ignoriert wird(kein Laufrahmen
um den Bereich, keine Kopie. Das Makro läuft aber durch). Wenn ich die folgenden 4 Zeilen herauskopiere, mit Sub und End Sub versehe und in ein neues Workbook eintrage, funzt es tadellos. Weiter ganz unten!
Workbooks("Lieferantenliste.xls").Activate
Worksheets("Tabelle2").Range("K4:K100").Copy
Workbooks(neuDatum).Activate
Worksheets("Tabelle1").Range("P1").PasteSpecial Paste:=xlPasteValues
Dim rng As Range, rngCell As Range
Dim iRow As Integer
iRow = 1
Range("P1:P100").Select
Selection.Sort Key1:=Range("P1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("Q1:Q100").Clear
Range("P1:P100").Interior.ColorIndex = 0
Range("Q1:Q100").Interior.ColorIndex = 0
Set rng = Range("B7:N42").CurrentRegion
For Each rngCell In rng.Cells
If WorksheetFunction.CountIf(rng, rngCell.Value) > 1 Then
If WorksheetFunction.CountIf(Columns(17), rngCell.Value) < 1 Then
iRow = iRow + 1
Cells(iRow, 1).Value = rngCell.Value
End If
End If
Next rngCell
Range("Q1:Q100").Select
Selection.Sort Key1:=Range("Q1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Dim LoI As Long
Dim LoJ As Long
Dim LoLetzte16 As Long
Dim LoLetzte17 As Long
Dim BoNein As Boolean
LoLetzte16 = 100
With Worksheets("Tabelle1")
If .Range("P1") = "" Then LoLetzte16 = .Range("P1:P100").End(xlUp).Row
End With
LoLetzte17 = 100
With Worksheets("Tabelle1")
If .Range("Q1") = "" Then LoLetzte17 = .Range("Q1:Q100").End(xlUp).Row
End With
For LoI = 1 To LoLetzte16
For LoJ = 1 To LoLetzte17
If Worksheets("Tabelle1").Cells(LoI, 16) = Worksheets("Tabelle1").Cells(LoJ, 17) Then
Worksheets("Tabelle1").Range("Q1:Q100").Interior.ColorIndex = 4
BoNein = True
End If
Next LoJ
If BoNein = False Then
Worksheets("Tabelle1").Cells(LoI, 16).Interior.ColorIndex = 3
End If
BoNein = False
Next LoI
End Sub

Warum ist das so, wo ist da der Fehler?
Da ist noch so ein Ding das Kopfschmerzen bereitet aber dazu ein anderes mal mehr.
Wer weiß Abhilfe?
Danke an alle Interesierten
Gruß Thomas

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Copy Befehl wird ignoriert
Ramses
Hallo
Das Makro funktioniert, allerdings habe ich noch einige Bemerkungen dazu

Private Sub Workbook_Open()
Worksheets("Tabelle1").Activate
Dim neuDatum As String
Dim neuPrüfen As VbMsgBoxResult
Do
neuDatum = InputBox("Datum einfügen TT-MM-JJ")
If neuDatum = Empty Then
neuPrüfen = MsgBox("Die Datei wird ohne Anschließendes speichern geöffnet!", vbOKOnly)
'Was passiert hier ?
'Du steigst einfach aus dem Makro aus
Exit Sub
End If
If IsDate(neuDatum) Then Exit Do Else
neuPrüfen = MsgBox("Falsches Format oder ungültiges Datum! Erneute Eingabe?", vbYesNo)
If neuPrüfen = vbNo Then
ActiveWorkbook.Close SaveChanges:=True
Else
End If
Loop
Range("N2").Select
Selection.Range("N2").Insert
ActiveCell.FormulaR1C1 = neuDatum
'Kann nicht funktionieren, weil die XLS-Extension fehlt
'Die Datei findest du nicht mehr
neuDatum = neuDatum & ".xls"
ActiveWorkbook.SaveAs neuDatum
'Zwei Zeilen weiter steht der Copy Befehl, der ignoriert wird(kein Laufrahmen
'um den Bereich, keine Kopie. Das Makro läuft aber durch). Wenn ich die folgenden 4 Zeilen herauskopiere, mit Sub und End Sub
versehe und in ein neues Workbook eintrage, funzt es tadellos. Weiter ganz unten!
Workbooks("Lieferantenliste.xls").Activate
Worksheets("Tabelle2").Range("K4:K100").Copy
Workbooks(neuDatum).Activate
Worksheets("Tabelle1").Range("P1").PasteSpecial Paste:=xlPasteValues
Dim rng As Range, rngCell As Range
Dim iRow As Integer
iRow = 1
Range("P1:P100").Select
Selection.Sort Key1:=Range("P1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("Q1:Q100").Clear
Range("P1:P100").Interior.ColorIndex = 0
Range("Q1:Q100").Interior.ColorIndex = 0
'Bis hierher getestet und läuft einwandfrei
'----------------
Set rng = Range("B7:N42").CurrentRegion
For Each rngCell In rng.Cells
If WorksheetFunction.CountIf(rng, rngCell.Value) > 1 Then
If WorksheetFunction.CountIf(Columns(17), rngCell.Value) iRow = iRow + 1
Cells(iRow, 1).Value = rngCell.Value
End If
End If
Next rngCell
Range("Q1:Q100").Select
Selection.Sort Key1:=Range("Q1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Dim LoI As Long
Dim LoJ As Long
Dim LoLetzte16 As Long
Dim LoLetzte17 As Long
Dim BoNein As Boolean
LoLetzte16 = 100
With Worksheets("Tabelle1")
If .Range("P1") = "" Then LoLetzte16 = .Range("P1:P100").End(xlUp).Row
End With
LoLetzte17 = 100
With Worksheets("Tabelle1")
If .Range("Q1") = "" Then LoLetzte17 = .Range("Q1:Q100").End(xlUp).Row
End With
For LoI = 1 To LoLetzte16
For LoJ = 1 To LoLetzte17
If Worksheets("Tabelle1").Cells(LoI, 16) = Worksheets("Tabelle1").Cells(LoJ, 17) Then
Worksheets("Tabelle1").Range("Q1:Q100").Interior.ColorIndex = 4
BoNein = True
End If
Next LoJ
If BoNein = False Then
Worksheets("Tabelle1").Cells(LoI, 16).Interior.ColorIndex = 3
End If
BoNein = False
Next LoI
End Sub
Gruss Rainer
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige