Thread: Slow Code
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Martin Brown Martin Brown is offline
external usenet poster
 
Posts: 230
Default Slow Code

dmoney wrote:
Calc mode did not help -- there are no formulas in the data and the set
command is automatically removed after i type it in the editor -I appreciate
the attempt - any other ideas - perhaps another method to remove leading edge
spaces from all cells in a sheet.


It might be worth printing out the actual bounds of the range, and a
progress counter every 100 or so rows processed. Excel 2007 can be
glacially slow for moderately sized datasets under some circumstances.

But usually it requires charts and formulae to be present.

Try doubling the size of the file and see if you can predict how long it
should take to handle 67000 lines.
BTW does it work OK for 65535 or fewer lines ?

Regards,
Martin Brown



"Jim Cone" wrote:

I know that MS's latest fad language doesn't require the use of "Set" statements.
However, give it a try and see if it makes a difference...
Set wsh = AppExcel.Application.ActiveSheet.UsedRange

You should also turn off calculation and reinstate it at the end of your code...
AppExcel.Calculation = xlCalculationManual
'other code
AppExcel.Calculation = xlCalculationAutomatic

Also, the UsedRange can often be much larger than the actual area containing data.
Futhermore, there is no "ActiveSheet" if you are automating Excel from another application,
unless you specifically make the Excel application visible.
--
Jim Cone
Portland, Oregon USA



"dmoney"
wrote in message ...
Hello gang -- I am writing an app in vb.net to manipulate some excel files.
the following code works fine on small files (1200 lines) but either takes
forever or fails on large files (67000 lines). im using excel 2007. for each
excel file, i create and instance of excel and leave open for saving
purposes. All this code does is trim the sheet.

AppExcel.Application.ScreenUpdating = False
Dim rng As Excel.Range
Dim wsh As Excel.Range

wsh = AppExcel.Application.ActiveSheet.UsedRange

For Each rng In wsh
rng.Value = LTrim(rng.Value)
Next rng
AppExcel.Application.ScreenUpdating = True

Any help is appreciated.
.