LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default poor macro performance

I have a macro to read in the a comma seperated value (CSV) file and
set the data into a named range. The file format is
<range_name,<numeric value. The problem is that the macro takes about
8 minutes to read 34000 records and seems to gradually slow down.
This would lead me to believe I have a memory leak of some kind. Most
of the time is split evenly between two functions
1) getRangeAddress2() to get the worksheet name range
2) Range(ra) = dprecord(1) to set the actual range value.

Any suggestions?
Paul
-------------------------------------------------------------------
Public Sub readDatapoints()
'Macro readDataPoints
'This macro will read in the a comma seperated value (CSV) file of
datapoints
'and set the data into a named range.

Dim sFile As String
Dim currentLine As String
Dim delimit As String
Dim counter As Integer
Dim ra As String
Dim fs As Object
Dim ts As Object
Dim dprecord

Dim oldStatusBar As Boolean

delimit = ","

'prompt user for file
sFile = Application.GetOpenFilename(fileFilter:="CSV Comma
delimited (*.csv), *.csv", Title:="BCAR data")
If Not Len(Dir(sFile)) 0 Or sFile = "False" Then
Exit Sub
End If

'We turn off calculation and screenupdating to speed up the macro.
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(sFile, 1, False)

currentLine = ts.ReadLine

oldStatusBar = Application.DisplayStatusBar

' Continues reading lines until there are no more.
While (Not ts.AtEndOfStream)

'give the user something to look at
If counter Mod 100 = 0 Then
Application.StatusBar = "loading BCAR data" &
String(counter / 100, ".")
End If

'parse the record
dprecord = Split(currentLine, delimit)

'read in the records and set the referenced range value
If UBound(dprecord) 0 And Len(dprecord(1)) 0 Then
' get the range address
ra = getRangeAddress2("DPA_" & CStr(dprecord(0)))

'set the value for the incoming record
If Len(ra) 0 Then
Range(ra) = dprecord(1)
End If
End If

currentLine = ts.ReadLine
counter = counter + 1
Wend

Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

Private Function getRangeAddress2(rname As String) As String
Dim c As Range
Dim returnStr As String

'''''''''''''''''''''''''''''''''''
' find the datapoint address name
''''''''''''''''''''''''''''''''''
'Dim lookuprange As Range
'Set lookuprange =
Worksheets("DPA_Control").Range("DPAControl_Range" )
'returnStr = Application.WorksheetFunction.VLookup(rname,
lookuprange, 2, False)

Set c = Worksheets("DPA Control").Cells.Find(What:=rname,
LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)



'if found, build and return address
If Not c Is Nothing Then
returnStr = c.Offset(0, 1).Value
returnStr = "='" & Replace(returnStr, "'", "''") & "'!" & rname
End If

Set c = Nothing

getRangeAddress2 = returnStr


End Function

 
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
Very poor performance with Excel 2007 RossR Excel Discussion (Misc queries) 3 March 29th 07 12:12 AM
Performance in excel 97 is poor cctd Excel Discussion (Misc queries) 1 January 5th 06 03:12 PM
C# worksheet function poor performance Simon Murphy[_4_] Excel Programming 0 June 22nd 05 01:43 AM
poor subroutine performance Alex East Excel Programming 1 February 27th 04 06:39 PM
Poor Worksheet Performance MD Excel Programming 6 August 5th 03 03:41 PM


All times are GMT +1. The time now is 07:14 AM.

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

About Us

"It's about Microsoft Excel"