홈>
내 코드의 일부입니다. 간단하게 만들 수있는 방법이 있습니까? 감사합니다.
For i = 2 To ws.Range("E1").CurrentRegion.Rows.Count
If ws.Cells(i, 4).Value Like ("*SSI*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Settlement instruction*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*delivery Instruction*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Request form*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.cells(i, 4).Value Like ("*Sales to onboarding*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Application*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Doc Check list*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Prime to Credit*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Prime to Legal*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Prime_Legal*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Prime_Credit*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*LEXIS*") Then ws.Cells(i, 4).EntireRow.Delete
If ws.Cells(i, 4).Value Like ("*Withdrawal Request*") Then ws.Cells(i, 4).EntireRow.Delete
Next i
- 답변 # 1
- 답변 # 2
이 라인을 따라 시도해 볼 수 있습니다
Sub del() Dim a As Variant Dim s As Variant Dim r As Range Dim l As Long a = Array("*abc*", "*def*", "efg*", "abcdef*hi") Set r = Range("a1:a20") For l = r.Rows.Count To 1 Step -1 For Each s In a If r.Cells(l, 1).Value Like s Then Rows(l).EntireRow.Delete Exit For End If Next s Next l End Sub
- 답변 # 3
루프를 뒤로 실행
재 계산 방지
한 번만 삭제
For i = ws.Range("E1").CurrentRegion.Rows.Count To 2 Step -1 DR = False Set r = ws.Cells(i, 4) s = r.Value If s Like ("*SSI*") Then DR = True If s Like ("*Settlement instruction*") Then DR = True If s Like ("*delivery Instruction*") Then DR = True If s Like ("*Request form*") Then DR = True If s Like ("*Sales to onboarding*") Then DR = True If s Like ("*Application*") Then DR = True If s Like ("*Doc Check list*") Then DR = True If s Like ("*Prime to Credit*") Then DR = True If s Like ("*Prime to Legal*") Then DR = True If s Like ("*Prime_Legal*") Then DR = True If s Like ("*Prime_Credit*") Then DR = True If s Like ("*LEXIS*") Then DR = True If s Like ("*Withdrawal Request*") Then DR = True If DR Then ws.Cells(i, 4).EntireRow.Delete Next i
- 답변 # 4
참고 :
<올>행이 삭제되면 셀이 위로 이동하여 아래 행에 동일한 행 번호가 적용되므로
i = i - 1
대신 루프를 사용하는 이유 행/e를 삭제 한 후 : 예 -1 단계를 사용하거나 다르게 작성할 수 있지만 다른 답변과 다른 것을 표시하고 싶습니다연산자처럼 사용할 필요가 없으며, vbs에서는 지원되지 않으므로 vbs를 배우기로 결정한 경우이를 피하는 것이 좋습니다
내 접근 방식은 배열에 키워드를 계속 추가하거나 컬렉션을 대신 만들 수 있습니다.
MyArr = Array("SSI", "Settlement instruction", "delivery Instruction", "Request form", "Sales to onboarding", "Application", "Doc Check list", "Prime to Credit", "Prime to Legal", "Prime_Legal", "Prime_Credit", "LEXIS", "Withdrawal Request") LastRow = ws.Range("E1").CurrentRegion.Rows.count i = 1 Do Until i > LastRow i = i + 1 cVal = ws.Cells(i, 4).Value For Each ma In MyArr If InStr(1, cVal, ma) > 0 Then ws.Cells(i, 4).EntireRow.Delete i = i - 1 'cells below will shift up, so next row will have the same row number Exit For End If Next Loop
관련 자료
- sql - LIKE 연산자는 어떻게 사용하나요?
- php 8 - PHP에서 "Nullsafe 연산자"를 어떻게 사용할 수 있습니까?
- VBA를 사용하여 Excel 시트의 행을 복사하고 CSV로 보내려면 어떻게해야합니까?
- mysql - SQL의 Like 연산자에서 모음을 얻는 방법은 무엇입니까?
- ios - 신속한 사용법 또는 운영자
- excel - VBA를 사용하여 한 행을 여러 행에 복사하는 방법
- excel - Where Like (SQL) VBA
- javascript - for 루프를 사용하여 사용자가 삽입 한 숫자를 합하는 방법은 무엇입니까?
- c# - 내 코드에서이 Crc32 클래스를 사용하는 방법
- javascript - Vue 3 사용 및 플러그인 Boostrap-vue 추가 방법?
- mysql - LEFT JOIN으로 WHERE 조건을 사용하는 방법은 무엇입니까?
- postgresql - 조인 SQL 쿼리에서 Case를 사용하는 방법
- C에서 realloc을 사용하는 방법
- javascript - Thymeleaf에서 DataTable을 사용하는 방법?
- next.js - NextJS에서 Linaria를 어떻게 사용할 수 있습니까?
- c# - ASPNET에서 ConcurrentDictionary 및 Task를 사용하는 방법
- node.js - FFMPEG 및 노드에서 스트림을 사용하는 방법
- string - Ruby 변수 인수에서 "# {…}를 사용하는 방법?
- python - pip로 설치할 때 git repo에서 py 스크립트를 사용하는 방법
- keras - 텍스트 분류에 GPT 3를 어떻게 사용할 수 있습니까?
관련 질문
- Excel VBA에서 열에서 키워드 찾기 및 다른 열 편집
- vba : 여러 값이 있는 여러 텍스트 오프셋을 어떻게 찾을 수 있습니까?
- Excel 2007의 텍스트를 Sharepoint 사이트의 .txt 파일에 쓰면 런타임 오류 '76' 경로를 찾을 수 없습니다.
- excel : 셀 색상을 확인/변경하기 위해 Change(byVal Target as Range)를 어떻게 사용합니까?
- excel : PC 스토리지 드라이브 이름 찾기
- excel : 성공적인 브라우저 시작 요청에 대한 동일한 페이로드에도 불구하고 VBA가 있는 HTTPRequest를 통한 "잘못된 다중 부분 페이로드 형식"
- excel : 수식 숫자 값을 숫자 더하기 1로 바꾸기
- excel : 값이 날짜를 따르도록 vlookup 또는 매크로를 설정하는 방법
- excel : 다른 이름으로 저장하는 동안 파일을 바꾸라는 메시지가 표시되면 "아니요" 또는 "취소"를 선택하면 VBA 1004 오류가 발생합니다.
- Excel 스프레드시트에 값을 쓰도록 확인란을 얻으려고 합니다.
이 작업을 수행하는 방법은 많이 있지만 여기에 하나가 있습니다 :
먼저 행을 삭제할 때 항상 범위의 맨 아래에서 시작하여 위로 이동하십시오. 이렇게하면 삭제시 행 건너 뛰기가 방지됩니다.
쉼표를 사용하여 텍스트를 분할하여 배열을 만들었습니다. 데이터에 쉼표가 포함되어 있으면 변경해야합니다.