Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
640to644
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
640to644
640to644
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Makro kürzen

Makro kürzen
23.07.2005 11:55:25
Thomas
Hallo Excelfreunde,
kann man dieses Makro etwas kürzer gestalten?

Sub FindenUndKopieren()
Dim iRowS As Integer, iRowT As Integer
Dim sWord As String
Dim i As Double
sWord = InputBox( _
prompt:="Suchbegriff:", _
Default:="")
If sWord = "" Then Exit Sub
iRowS = 1
iRowT = 1
With Worksheets("Tabelle2")
Do Until IsEmpty(Cells(iRowS, 1))
If Cells(iRowS, 1) = sWord Then
Rows(iRowS).Copy .Rows(iRowT)
iRowT = iRowT + 1
End If
iRowS = iRowS + 1
Loop
.Columns.AutoFit
.Select
End With
Rows("1:30").Insert Shift:=xlDown
Sheets("Artikel-Verzeichnis").Select
sWord = InputBox( _
prompt:="Suchbegriff:", _
Default:="")
If sWord = "" Then Exit Sub
iRowS = 1
iRowT = 1
With Worksheets("Tabelle2")
Do Until IsEmpty(Cells(iRowS, 1))
If Cells(iRowS, 1) = sWord Then
Rows(iRowS).Copy .Rows(iRowT)
iRowT = iRowT + 1
End If
iRowS = iRowS + 1
Loop
.Columns.AutoFit
.Select
End With
Rows("1:30").Insert Shift:=xlDown
Sheets("Artikel-Verzeichnis").Select
sWord = InputBox( _
prompt:="Suchbegriff:", _
Default:="")
If sWord = "" Then Exit Sub
iRowS = 1
iRowT = 1
With Worksheets("Tabelle2")
Do Until IsEmpty(Cells(iRowS, 1))
If Cells(iRowS, 1) = sWord Then
Rows(iRowS).Copy .Rows(iRowT)
iRowT = iRowT + 1
End If
iRowS = iRowS + 1
Loop
.Columns.AutoFit
.Select
End With
Rows("1:30").Insert Shift:=xlDown
Sheets("Artikel-Verzeichnis").Select
sWord = InputBox( _
prompt:="Suchbegriff:", _
Default:="")
If sWord = "" Then Exit Sub
iRowS = 1
iRowT = 1
With Worksheets("Tabelle2")
Do Until IsEmpty(Cells(iRowS, 1))
If Cells(iRowS, 1) = sWord Then
Rows(iRowS).Copy .Rows(iRowT)
iRowT = iRowT + 1
End If
iRowS = iRowS + 1
Loop
.Columns.AutoFit
.Select
End With
For i = 1000 To 1 Step -1
If Cells(i, 1).Value = "" Then _
Cells(i, 1).EntireRow.Delete
Next i
End Sub

Muss ungefähr 20 bis 50 Artikelnummer so suchen und in Tabelle2 Kopieren.
Für eine Antwort bedanke ich mich bereits jetzt!
Thomas.

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Makro kürzen
23.07.2005 15:04:14
Reinhard
Hi Thomas,
With Worksheets("Tabelle2")
Do Until IsEmpty(Cells(iRowS, 1))
If Cells(iRowS, 1) = sWord Then
Rows(iRowS).Copy .Rows(iRowT)
iRowT = iRowT + 1
End If
iRowS = iRowS + 1
Loop
.Columns.AutoFit
.Select
End With
kann man kürzen zu:
With Worksheets("Tabelle2")
For n = 1 To .Cells(65536, 1).End(xlUp).Row
If Cells(n, 1) = sWord Then Rows(iRowS).Copy .Rows(iRowT)
Next n
.Columns.AutoFit
.Select 'wofür das Select wenn du gleich danach Sheets("Artikel-Verzeichnis").Select machst?
End With

und da du diese Schleife mehfach hast, würde ich das in eine Sub auslagern
sub xyz(name as String, iRows as long, iRowT as long)
...
end sub
dann mit call xyz("Tabelle2",17,34) aufrufen.
Mach das und dann poste nochmal den Code, irgendwie geschieht da einiges doppelt auf den flüchtigen Blick.
.Cells(65536, 1).End(xlUp).Row hat exakt 2 Fehlermöglichkeiten, also falsches Ergebnis, wenn zelle in zeile 65536 nicht leer ist (unwahrscheinlich), oder wenn die Spalte ganz leer ist, letzteres kannst du mit IIF bequem abfangen.
Gruß
Reinhard
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige