ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete Rows on Conditions & Long Processing Time (https://www.excelbanter.com/excel-programming/450849-delete-rows-conditions-long-processing-time.html)

JeanPierre Charron

Delete Rows on Conditions & Long Processing Time
 
Problem # 1 : Delete Rows if Col "A" Cells < ("P1" OR "P2")
Delete Rows if Col "B" = "B"
Row 1 Col A Col B
Row 2 P1 A
Row 3 P3 B
Row 4 P1 A
Row 5 P1 B
Row 6 P2 B
Row 7 P2 A
Row 8 P3 A
..
Expected result : Rows 2, 4, 7 would be kept
My Code gives abnormal results.
..
Problem # 2 : Abnormal processing Time over 8 minutes on 15,000 records.
I suspect my code needs to be re-written.
-----------------------------------
Sub DeleteRows()
Dim strCheck As String
Dim LRow As Long, i As Long
Dim varData As Variant

With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

strCheck = "P1,P2"

With Sheets("PM4")
LRow = .Cells(Rows.Count, 1).End(xlUp).Row
varData = .Range("A2:A" & LRow)
For i = UBound(varData) To LBound(varData) Step -1
If InStr(strCheck, varData(i, 1)) = 0 Then
Rows(i + 1).Delete
End If
Next
End With
With Sheets("PM4")
LRow = .Cells(Rows.Count, 1).End(xlUp).Row
varData = .Range("B2:B" & LRow)
For i = UBound(varData) To LBound(varData) Step -1
With .Cells(i, "B")
If Not IsError(.Value) Then
If .Value = "B" Then .EntireRow.Delete
End If
End With
Next
End With
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub

Claus Busch

Delete Rows on Conditions & Long Processing Time
 
Hi J.P.,

Am Mon, 4 May 2015 11:10:47 -0700 (PDT) schrieb JeanPierre Charron:

try:

Sub DeleteRows()
Dim strCheck As String
Dim LRow As Long, i As Long
Dim varData As Variant

With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

strCheck = "P1,P2"

With Sheets("PM4")
LRow = .Cells(Rows.Count, 1).End(xlUp).Row
varData = .Range("A2:B" & LRow)
For i = UBound(varData) To LBound(varData) Step -1
If InStr(strCheck, varData(i, 1)) = 0 Or varData(i, 2) = "B"
Then
Rows(i + 1).Delete
End If
Next
End With

With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional

nuochoa080415

xem truyện tranh nữ hoàng ai cập tập 20 Một học sinh đi chơi về tuyên bố với cả pḥng:

Cuối cùng rồi cũng có người con gái dám liều ḿnh v́ tao. Cả pḥng nhao nhao:

- Ai vậy mày, nhỏ nào nói nghe coi?

- Nhỏ Hồng bên lớp sử chứ ai!

- Nhỏ nói ǵ với mày?

- Nhỏ nói “Yêu ông ư? Tui thà nhảy lầu c̣n hơn”. Xem thêm đọc truyện tranh nư hoàng ai cập tập 4


All times are GMT +1. The time now is 11:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com