Frage
15.02.2018 22:48:27
Peter(silie)
Hallo,
unten nicht getesteter Code:
Option Explicit
'nach einem treffer aufhören
Public Sub DeleteRow()
Dim ws As Worksheet
Dim rng As Range, c As Range
Dim row_ As Long
Dim Variable1 As String
Variable1 = "was auch immer"
Set ws = ThisWorkbook.Sheets("Tabelle3")
With ws
lROw = .Cells(.Rows.Count, 13).End(xlUp).Row
Set rng = .Range(.Cells(1, 13), .Range(lROw, 13))
Set c = rng.Find(Variable1, xlFormulas, xlWhole, xlNext)
If Not c Is Nothing Then
fa = c.Address
Do
If .Cells(c.Row, 4).Value = vbNullString Then
c.EntireRow.Delete
Else
Set c = rng.FindNext(c)
End If
Loop While Not c Is Nothing And c.Address fa
End If
End With
End Sub
'Komplettdurchlauf
Public Sub DeleteRows()
Dim ws As Worksheet
Dim rng As Range, c As Range
Dim row_ As Long, fa As String
Dim indizes() As Long, n As Long
Set ws = ThisWorkbook.Sheets("Tabelle3")
With ws
lROw = .Cells(.Rows.Count, 13).End(xlUp).Row
Set rng = .Range(.Cells(1, 13), .Range(lROw, 13))
Set c = rng.Find("Suchwert", xlFormulas, xlWhole, xlNext)
If Not c Is Nothing Then
fa = c.Address
Do
If .Cells(c.Row, 4).Value = vbNullString Then
ReDim Preserve indizes(n)
indizes(n) = c.Row
n = n + 1
End If
Set c = rng.FindNext(c)
Loop While Not c Is Nothing And c.Address fa
End If
End With
End Sub
Private Sub Execute(ByRef indizes As Variant)
Dim i As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Tabelle3")
With ws
For i = UBound(indizes) To LBound(indizes) Step -1
.Cells(i, 1).EntireRow.Delete
Next i
End With
End Sub