VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Excel Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 04-14-2012, 05:24 AM   #1
copyt

 
Joined: Mar 2012
Posts: 55
Kb Entries: 0
Articles: 0
Solved: Speed up excel code

Hello all, I have a code (recorded macro) to search and delete rows containing certain texts. Since the data is in rangeA1:A30000 so it takes a long time to finish. Any idea to speed it up? Any help/suggestion would be appreciated.

VBA:
Sub import_MGF_distiller_part01() Application.ScreenUpdating = False Columns("A:A").Select Selection.AutoFilter ActiveSheet.Range("$A$1:$A$5").AutoFilter Field:=1, Criteria1:="=*#*", _ Operator:=xlOr, Criteria2:="=*END*", Operator:=xlAnd Selection.EntireRow.Delete Shift:=xlUp Application.ScreenUpdating = False Columns("A:A").Select Selection.AutoFilter ActiveSheet.Range("$A$1:$A$5").AutoFilter Field:=1, Criteria1:="=*BEGIN*", _ Operator:=xlOr, Criteria2:="=*TITLE*", Operator:=xlAnd Selection.EntireRow.Delete Shift:=xlUp Application.ScreenUpdating = False Columns("A:A").Select Selection.AutoFilter ActiveSheet.Range("$A$1:$A$5").AutoFilter Field:=1, Criteria1:="=*SCANS*", _ Operator:=xlOr, Criteria2:="=*RAWSCANS*", Operator:=xlAnd Selection.EntireRow.Delete Shift:=xlUp Application.ScreenUpdating = False Columns("A:A").Select Selection.AutoFilter ActiveSheet.Range("$A$1:$A$5").AutoFilter Field:=1, Criteria1:="=*RTINSECONDS*", _ Operator:=xlOr, Criteria2:="=*_DISTILLER_*", Operator:=xlAnd Selection.EntireRow.Delete Shift:=xlUp End Sub
VBA tags courtesy of www.thecodenet.com

Local Time: 04:32 PM
Local Date: 06-19-2013

 
Reply With Quote Top
Old 04-14-2012, 07:25 AM   #2
xld
 
xld's Avatar
Distinguished Lord of VBAX

 
Joined: Apr 2005
Posts: 23,118
Kb Entries: 3
Articles: 2
See if this is quicker

VBA:
Sub import_MGF_distiller_part01() Dim rng As Range Dim lastrow As Long Application.ScreenUpdating = False With ActiveSheet lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row .Columns("B").Insert .Range("B1").Value = "tmp" .Range("B2").Resize(lastrow - 1).Formula = "=OR(ISNUMBER(SEARCH(""#"",A2)),ISNUMBER(SEARCH(""END"",A2))," & _ "ISNUMBER(SEARCH(""BEGIN"",A2)),ISNUMBER(SEARCH(""TITLE"",A2))," & _ "ISNUMBER(SEARCH(""SCANS"",A2)),ISNUMBER(SEARCH(""ROWSCANS"",A2))," & _ "ISNUMBER(SEARCH(""RTINSECONDS"",A2)),ISNUMBER(SEARCH(""_DISTILLER_"",A2)))" Set rng = .Range("B1").Resize(lastrow) rng.AutoFilter rng.AutoFilter Field:=1, Criteria1:="=TRUE" On Error Resume Next Set rng = rng.Offset(1, 0).SpecialCells(xlCellTypeVisible) On Error Goto 0 If Not rng Is Nothing Then rng.EntireRow.Delete End If .Columns("B").Delete End With Application.ScreenUpdating = True End Sub
VBA tags courtesy of www.thecodenet.com


____________________________________________
Nihil simul inventum est et perfectum

Abusus non tollit usum

Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber

Local Time: 01:32 AM
Local Date: 06-20-2013
Location:

 
Reply With Quote Top
Old 04-14-2012, 01:38 PM   #3
copyt

 
Joined: Mar 2012
Posts: 55
Kb Entries: 0
Articles: 0
@ xld

Thank you very much. Yours is much faster.

Local Time: 04:32 PM
Local Date: 06-19-2013

 
Reply With Quote Top
Old 04-15-2012, 08:45 AM   #4
snb

 
Joined: Apr 2012
Posts: 1,191
Kb Entries: 0
Articles: 4
or
VBA:
Sub snb() With application .screenupdating=False .calculation= xlcalculationmanual For j=1 To 6 columns(1).replace choose(j,"*#*","END*","*BeGIN*","*TITLE*","*SCANS*","*RTINSECONDS*","*_DISTILLER_*"),"",xlpart Next columns(1).specialcells(4).entirerow.delete .calculation=xlcalculationautomatic .screenupdating=True End With End Sub
VBA tags courtesy of www.thecodenet.com

Local Time: 02:32 AM
Local Date: 06-20-2013

 
Reply With Quote Top
Old 04-15-2012, 11:03 PM   #5
copyt

 
Joined: Mar 2012
Posts: 55
Kb Entries: 0
Articles: 0
@ snb

Thank you very much.

Local Time: 04:32 PM
Local Date: 06-19-2013

 
Reply With Quote Top
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 05:32 PM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express