View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Klips Klips is offline
external usenet poster
 
Posts: 6
Default vba Code Performance

Hi all,

I am experiencing a performance issue with my vba code. I think that
I'm making a mistake somewhere since a similar code this used to run
alot faster. Here are the details:

- I have tested the code on both Excel 2002 and 2003
- The code that seems to be causing the problem is this:

Sub importItems(ByRef sourceRange as Range, ByRef destinRange as
Range, ByRef sourceWB As Workbook, ByRef rowTotal As Long)

On Error GoTo ErrHandler:

Dim dataRow as Range
Dim rowCount as Long
Dim readRows as Long
Dim totalRows as Long
rowCount = 0
readRows = 0
totalRows = sourceRange.Rows.Count
For Each dataRow in sourceRange.Rows
If dataRow.Cells(1, 2) = "Yes" Then
With dataRow
rowCount = rowCount + 1
destinRange.Cells(rowCount, 1) = .Cells(1, 1)
destinRange.Cells(rowCount, 2) = .Cells(1, 9)
destinRange.Cells(rowCount, 8) = WorksheetFunction.VLookup(.Cells(1,
14), sourceWB.Sheets("Releases").Range("Data"), 2, False)
destinRange.Cells(rowCount, 9) = .Cells(1, 7)
End With
End If
readRows = readRows + 1
frmImport.prg_import.Value = (readRows / totalRows) * 100
Next dataRow
rowTotal = rowCount
Exit Sub

ErrHandler:
MsgBox "An error occured: " & Err.Description & " (" & Err.Number &
")", vbCritical, "Temp Data Procedure Error"

End Sub

- The code is intended to import some data from another excel file.
The amount of data that is transfered is about 13 x 1600.

The function works, but it is extremely slow. I had pretty much the
same code inside my calling function and it was a lot faster. Once I
moved the code into a seperate procedure, the performance took a big
hit. I'm not sure what could be the problem. If anyone wants to see
the complete file, I'll be happy to provide it.

Thanks in advance for all help