K 열의 이메일 주소 그룹을 검색하고 @ noemail.com이있는 모든 행을 삭제해야합니다. 아래는 내 코드 시도입니다. 이전에는 작동했지만 한 번에 하나의 행만 삭제하여 매크로를 여러 번 실행해야했습니다.
`Sub Prospects()
'
' Prospects Macro
'
' Delete rows with @noemail.com
Dim rng As Range
Dim row As Range
Dim ContainWord As String
' Select range in column K
Range("K2").Select
Range(Selection, Selection.End(xlDown)).Select
Set rng = Selection
' Set noemail as word to search for
ContainWord = "noemail"
' Loop through each cell in range, test cell contents and clear noemail.com rows
For Each row In rng.Cells
If Not row.Find(ContainWord) Is Nothing Then rng.EntireRow.Delete
Next row
Range("B2").Select
End Sub
문제는 다음 줄에 있습니다.
If Not row.Find(ContainWord) Is Nothing Then rng.EntireRow.Delete
특히 마지막 부분 : rng.EntireRow.Delete
. rng
필터링 된 것만이 아니라 전체 선택입니다. 셀 단위로 이동 한 다음 True를 반환하는 항목을 찾으면 맨 위 행을 삭제합니다.rng
로 변경 rng
하면 row
다음과 같이 원하는 효과를 얻을 수 있습니다.
If Not row.Find(ContainWord) Is Nothing Then row.EntireRow.Delete
루프를 처리하도록 편집 :
문제는 라인을 삭제하면 다음 셀로 이동한다는 것입니다. 삭제 된 항목 바로 아래 줄에 "noemail"이 있으면 해당 항목을 방금 테스트 한 행으로 이동하고 건너 뜁니다.
이 시도:
Sub Prospects()
' Delete rows with @noemail.com
Dim ContainWord As String
Dim i As Integer
i = 2 ' i is a counter
' Set noemail as word to search for
ContainWord = "noemail"
' Loop through each cell in column K, test cell contents and clear noemail.com rows
Do While Range("K" & i) <> ""
If Not Range("K" & i).Find(ContainWord) Is Nothing Then
Range("K" & i).EntireRow.Delete
Else
i = i + 1
End If
Loop
Range("B2").Select
End Sub`
이것은 좋은 주소를 만나고 다음 주소로 이동할 때까지 잘못된 주소를 삭제하는 동일한 행에 유지됩니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다