Live-Forum - Die aktuellen Beiträge
Datum
Titel
17.10.2025 10:28:49
16.10.2025 17:40:39
Anzeige
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Makro kürzen

Forumthread: 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.
Anzeige

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
;

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Entdecke mehr
Finde genau, was du suchst

Die erweiterte Suchfunktion hilft dir, gezielt die besten Antworten zu finden

Suche nach den besten Antworten
Unsere beliebtesten Threads

Entdecke unsere meistgeklickten Beiträge in der Google Suche

Top 100 Threads jetzt ansehen
Anzeige