View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
BillReese BillReese is offline
external usenet poster
 
Posts: 4
Default Can someone help me with this slow code

Hi,
I have a VB application, which starts and controls Excel. The program reads
the data from over 20 ASCII files and extracts that data and stitches it
together into one workbook by copy and paste actions.

Here is my problem, I do a lot of other things with my data, that goes very
quickly... I mostly set ranges to do this and either move or modify data
as ranges, or worksheet formulas. This code I past below is one section
where I don't know how to work with it as a range.

My problem code iterates a column to and find any occurrence of the value
"0".. If it finds a Zero it's a bad reading recorded by this instrument (a
spectrometer).. then I need to replace it with the previous row's value
because an electrical dropout is not a real reading, and a ZERO give me
divide by Zero errors for my other formulas added to the main spreadsheet...

does anyone know of a faster way to do this code below. If I write this
code inside an Excel file as a local macro, it runs extremely swift, but
when I use Excel as a remote it takes maybe 20 to 50 seconds this relatively
small iteration.

can someone please help me on this?
================================================== ===================================
Dim Ws As Worksheet, x As Long, y As Long
Set Ws = ActiveSheet: y = 2
With Ws
Application.DisplayAlerts = False
For x = 1 To 2000
If (Cells((500 + x), y).Value = "0") Then
Cells((500 + x), y).Value = Cells((500 + (x - 1)), y).Value
End If
Next
End With
Application.DisplayAlerts = True
================================================== ===================================