の代わりにループして1により各セル1を参照するオフあなたより良いですアレイ;その後、バリアント配列をループします。
スターター:
Sub Sample()
' Look in Column D, starting at row 2
DeleteRowsWithValue "@", 4, 2
End Sub
実作業者:
Sub DeleteRowsWithValue(Value As String, Column As Long, StartingRow As Long, Optional Sheet)
Dim i As Long, LastRow As Long
Dim vData() As Variant
Dim DeleteAddress As String
' Sheet is a Variant, so we test if it was passed or not.
If IsMissing(Sheet) Then Set Sheet = ActiveSheet
' Get the last row
LastRow = Sheet.Cells(Sheet.Rows.Count, Column).End(xlUp).Row
' Make sure that there is work to be done
If LastRow < StartingRow Then Exit Sub
' The Key to speeding up the function is only reading the cells once
' and dumping the values to a variant array, vData
vData = Sheet.Cells(StartingRow, Column) _
.Resize(LastRow - StartingRow + 1, 1).Value
' vData will look like vData(1 to nRows, 1 to 1)
For i = LBound(vData) To UBound(vData)
' Find the value inside of the cell
If InStr(vData(i, 1), Value) > 0 Then
' Adding the StartingRow so that everything lines up properly
DeleteAddress = DeleteAddress & ",A" & (StartingRow + i - 1)
End If
Next
If DeleteAddress <> vbNullString Then
' remove the first ","
DeleteAddress = Mid(DeleteAddress, 2)
' Delete all the Rows
Sheet.Range(DeleteAddress).EntireRow.Delete
End If
End Sub
まず、横断する細胞の数を制限します。つまり、範囲(E:E)の代わりにデータが入った範囲を使用してください。 – shahkalpesh
私はいつもその方法を知っていました。最初のセルを含む範囲? – Parseltongue
http://www.rondebruin.nl/win/s4/win001.htm - これを見てください。私は確信しています、それはあなたのためにそれに答えるでしょう。あなたの質問をreged、セルA1のデータが含まれていると言い、今すぐCtrl +下矢印を押してください。 A1からデータを含む最後のセルまでのすべてのセルが選択されます(注:中央には空白のセルはありません)。 VBAを使用すると、 'lastCell = Range(" A1 ")。End(xlDown)' – shahkalpesh