Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 145
Default speeding up this code

Hi All,

I've got a directory listing dumped into an Excel sheet (created from the
command line with 'dir \s dir.txt'), which i am trying to get in to some
sort of order.

I've created the code below to check for certain text within cells and if
present, delete the containing row. The code works well enough, but as i
have 60,000 rows it is taking a VERY LONG time. is there any way to
significantly speed up this task?

'=========
Sub rowdel()

Dim Tcell As Range, x, y
x = 0
y = 0

For Each Tcell In Selection

If InStr(1, Tcell.Value, "<DIR .") 0 Then
Tcell.Rows.Delete
x = x + 1
End If

y = y + 1
Application.StatusBar = y

Next Tcell

MsgBox x & " lines removed"
Application.StatusBar = False

End Sub

'=========

Thanks for any help,

Tim


  #2   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 145
Default speeding up this code

Sorry for replying to my own post, but i just turned of screenupdating and
it speeded everything up nicely ;o)

"Tim" <tmarsh-trousers-@-take off my trousers to reply-blueyonder.co.uk
wrote in message ...
Hi All,

I've got a directory listing dumped into an Excel sheet (created from the
command line with 'dir \s dir.txt'), which i am trying to get in to some
sort of order.

I've created the code below to check for certain text within cells and if
present, delete the containing row. The code works well enough, but as i
have 60,000 rows it is taking a VERY LONG time. is there any way to
significantly speed up this task?

'=========
Sub rowdel()

Dim Tcell As Range, x, y
x = 0
y = 0

For Each Tcell In Selection

If InStr(1, Tcell.Value, "<DIR .") 0 Then
Tcell.Rows.Delete
x = x + 1
End If

y = y + 1
Application.StatusBar = y

Next Tcell

MsgBox x & " lines removed"
Application.StatusBar = False

End Sub

'=========

Thanks for any help,

Tim



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default speeding up this code

Try this
Dim Tcell As Range, x, y
x = 0
y = 0
Application.screenupdating = false
For Each Tcell In Selection

If InStr(1, Tcell.Value, "<DIR .") 0 Then
Tcell.Rows.Delete
x = x + 1
End If

y = y + 1
Application.StatusBar = y

Next Tcell

MsgBox x & " lines removed"
Application.StatusBar = False
Application.screenupdating = true
End Sub

"Tim" wrote:

Hi All,

I've got a directory listing dumped into an Excel sheet (created from the
command line with 'dir \s dir.txt'), which i am trying to get in to some
sort of order.

I've created the code below to check for certain text within cells and if
present, delete the containing row. The code works well enough, but as i
have 60,000 rows it is taking a VERY LONG time. is there any way to
significantly speed up this task?

'=========
Sub rowdel()

Dim Tcell As Range, x, y
x = 0
y = 0

For Each Tcell In Selection

If InStr(1, Tcell.Value, "<DIR .") 0 Then
Tcell.Rows.Delete
x = x + 1
End If

y = y + 1
Application.StatusBar = y

Next Tcell

MsgBox x & " lines removed"
Application.StatusBar = False

End Sub

'=========

Thanks for any help,

Tim



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default speeding up this code

Sub rowdel()
Dim Tcell As Range, x, y
Dim startCol As Long
Dim rng As Range

x = 0: y = 0


Set rng = Range(Cells(1, Selection.Cells(1, 1).Column),
Selection.End(xlDown))
startCol = rng.Column
Columns(startCol + 1).Insert
Cells(1, startCol + 1).Value = "temp"
With Cells(2, startCol + 1)
.FormulaR1C1 = "=AND(RC[-1]<"""",ISNUMBER(FIND(RC[-1],""<DIR
.."")))"
.AutoFill .Resize(rng.Rows.Count - 1)
End With

rng.Resize(, 2).AutoFilter field:=2, Criteria1:="=TRUE"

Set rng = rng.Offset(1, 0).SpecialCells(xlCellTypeVisible)
rng.EntireRow.Delete
Columns(startCol + 1).Delete
Application.StatusBar = False

End Sub




--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Tim" <tmarsh-trousers-@-take off my trousers to reply-blueyonder.co.uk
wrote in message ...
Hi All,

I've got a directory listing dumped into an Excel sheet (created from the
command line with 'dir \s dir.txt'), which i am trying to get in to some
sort of order.

I've created the code below to check for certain text within cells and if
present, delete the containing row. The code works well enough, but as i
have 60,000 rows it is taking a VERY LONG time. is there any way to
significantly speed up this task?

'=========
Sub rowdel()

Dim Tcell As Range, x, y
x = 0
y = 0

For Each Tcell In Selection

If InStr(1, Tcell.Value, "<DIR .") 0 Then
Tcell.Rows.Delete
x = x + 1
End If

y = y + 1
Application.StatusBar = y

Next Tcell

MsgBox x & " lines removed"
Application.StatusBar = False

End Sub

'=========

Thanks for any help,

Tim



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
Help speeding up my code Nick Excel Programming 7 December 15th 06 02:49 PM
speeding up copy and paste code cereldine[_18_] Excel Programming 1 April 20th 06 05:36 PM
Help on cleaning / speeding up code Chris Salcedo Excel Programming 2 October 17th 05 01:16 AM
Speeding Up Code [email protected] Excel Programming 8 August 31st 05 04:46 PM
Online Resources for Speeding Up Code orekin Excel Programming 1 July 8th 04 04:09 AM


All times are GMT +1. The time now is 11:52 AM.

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

About Us

"It's about Microsoft Excel"