Advertisement

06.03.2008 at 11:02PM PDT, ID: 23455689
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Excel VBA Application Very Slow with added Volume

Asked by jwbrown65 in Miscellaneous Programming, Visual Basic Programming

Tags: , , , , ,

Wrote (and borrowed some) a function which opens all the Excel files in a given directory, then pulls data off various sheets within each workbook and returns that data to a single, master file.

Each workbook contains approx 36000 rows of data all on disparate sheets within the file.  Each workbook has the same type of data, in the same cells on each sheet, so locating the data is not a challenge - writing back to the master file in a timely manner is.

When I load up a single file in this routine, the 36000+ rows of data are processed in less than 45 seconds.  When I load up multiple files, the program slows progressively in relation to the number of files loaded in the program at one time.  For example, If I load 5 files, each individual file creeps from 45 sec per to 3 min per.

Any tips for tuning this would be much appreciated.

------------------------------------------------------------------------------------------------


Sub ReadDataFromAllWorkbooksInFolder()
Dim FolderName As String, wbName As String, r As Long, cValue As Variant
Dim wbList() As String, wbCount As Integer, i As Integer, strWSname As String

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False



    FolderName = "C:\Users\User1\Documents\excel\"
    ' create list of workbooks in foldername
    wbCount = 0
    wbName = Dir(FolderName & "\" & "*.xls")
    While wbName <> ""
        wbCount = wbCount + 1
        ReDim Preserve wbList(1 To wbCount)
        wbList(wbCount) = wbName
        wbName = Dir
    Wend
    If wbCount = 0 Then Exit Sub
    ' get values from each workbook
   
    r = 0
    strWSname = "Front page"
    'populate columns from files
    c = 5
    For i = 1 To wbCount
        r = 6
        c = c + 1
        cValue = GetInfoFromClosedFile(FolderName, wbList(i), strWSname, "A6", "Names")
        Cells(r, c) = cValue    
    Next i
   
    v = 5
    'populate rows of data under columns
    For j = 1 To wbCount
    v = v + 1
   
   For q = 8 To 36038
    cellARef = "A" & q
    strWSname = Range(cellARef).Text
   
    cellBRef = "B" & q
    cellSearch = Replace(Range(cellBRef).Text, "$", "")
   
    cValue = GetInfoFromClosedFile(FolderName, wbList(j), strWSname, cellSearch, "Values")
    Cells(q, v) = cValue

    Next q
    Next j
   
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub

Private Function GetInfoFromClosedFile(ByVal wbPath As String, _
    wbName As String, wsName As String, cellRef, callType As String) As Variant
Dim arg As String
    GetInfoFromClosedFile = ""
    If Right(wbPath, 1) <> "\" Then wbPath = wbPath & "\"
    If Dir(wbPath & "\" & wbName) = "" Then Exit Function
    'Workbooks.Open (wbPath & "\" & wbName)
    Select Case callType
        Case "Names"
            arg = "'[" & wbName & "]" & _
                    wsName & " '!" & Range(cellRef).Address(True, True, xlR1C1)
        Case "Values"
            arg = "'[" & wbName & "]" & _
                wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
    End Select

    On Error Resume Next
    GetInfoFromClosedFile = ExecuteExcel4Macro(arg)
End FunctionStart Free Trial
[+][-]06.03.2008 at 11:40PM PDT, ID: 21707442

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Miscellaneous Programming, Visual Basic Programming
Tags: Microsoft, Excel VBA, 2003, VBA 6.5, IE 7.0, n/a
Sign Up Now!
Solution Provided By: JurgenDB
Participating Experts: 1
Solution Grade: B
 
 
[+][-]06.04.2008 at 05:32AM PDT, ID: 21709311

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628