대신 루프 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
첫째, 세포의 수가 통과하는 제한합니다. 즉, 'range (E : E)'대신 데이터가 포함 된 범위를 사용하십시오. – shahkalpesh
어떻게 그럴 수 있는지 항상 궁금해했습니다. 데이터가있는 마지막 셀까지 첫 번째 셀을 포함하는 범위를 선택하려면 어떻게해야합니까? ? – Parseltongue
http://www.rondebruin.nl/win/s4/win001.htm - 이것 좀보세요. 나는 확신한다, 그것은 당신을 위해 그것을 대답 할 것이다. 귀하의 질문에 reged, 셀 A1에 데이터가 들어 있다고 말하면 이제 Ctrl + 아래쪽 화살표를 누릅니다. A1에서 시작하여 데이터가 포함 된 마지막 셀까지의 모든 셀을 선택합니다 (참고 : 가운데에 빈 셀이 없어야 함). VBA를 사용하면'lastCell = Range ("A1") End (xlDown)' – shahkalpesh