Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default 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
  #3   Report Post  
Banned
 
Posts: 6
Default

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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting Rows on condition & Long processing time JeanPierre Charron Excel Programming 3 May 5th 15 06:12 PM
Delete Rows with Conditions Len Excel Programming 0 February 25th 11 01:00 AM
Processing taking a really long time SS Excel Discussion (Misc queries) 2 March 17th 09 02:19 PM
Delete Rows for given conditions. fpd833 Excel Programming 5 March 2nd 09 07:37 PM
How to delete blank rows at one time in a long excel spreadsheet? lkurokawa Excel Worksheet Functions 2 March 19th 08 09:01 PM


All times are GMT +1. The time now is 12:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"