데이터 집합을 정리하려고하는데 vba 함수 wholerow.delete에서 이상한 점을 발견했습니다. 다음 코드는 의도 한대로 취소 선 형식 인 경우 전체 행을 삭제하지만 바로 다음 행은 건너 뜁니다. 그것들도 그 형식이라면. 취소 선 형식이 아닌 행이 더 많은 행을 삭제하는 기능을 "재설정"하는 것처럼 보입니다. 아무도 이유를 알고 있거나 이것을 디버깅하기 위해 무엇을 할 수 있습니까?
For Each rng In rng1
'Check each character in the cell
For i = 1 To Len(rng.Value)
'If any letter is Strikethrough,delete entire column
If rng.Characters(i, 1).Font.Strikethrough = True Then
rng.Select 'just serves the purpose of observing which rows are being selected
rng.EntireRow.Delete
GoTo NextRng
End If
Next i
NextRng:
Next rng
다른 접근 방식을 사용하여 해결 방법을 찾았지만 매우 느립니다.
'Delete cells that have the strikethrough format - works but is super slow!
ws2.Range("B2").Activate
Do Until ActiveCell.Value = ""
If ActiveCell.Font.Strikethrough = True Then
ActiveCell.EntireRow.Delete
Else: ActiveCell.Offset(1, 0).Activate
End If
Loop
누구든지이 문제를 신속하게 해결할 수있는 대안이 있다면, 귀하의 의견에 대단히 감사하겠습니다.
빠른 응답 덕분에 나는 그것을 알아 냈습니다. 이 스레드에서 (약간) 더 빠른 방법으로 나를 밀어 준 @Siddarth Rout에게 특별히 감사드립니다. VBa 조건부 삭제 루프가 작동하지 않음 다음은 누군가가 궁금한 경우를 대비 한 작업 코드입니다.
Dim delRange As Range
Dim ws2 As Worksheet
Dim i As Long
'Find Lastrow in ws2
LastRow2 = ws2.Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
With ws2
For i = 1 To LastRow2
If .Cells(i, 2).Font.Strikethrough = True Then
'This if statement adds all the identified rows to the range that will be deleted
If delRange Is Nothing Then
Set delRange = .Rows(i)
Else
Set delRange = Union(delRange, .Rows(i))
End If
End If
Next i
If Not delRange Is Nothing Then delRange.Delete
End With
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다