+ Reply to Thread
Results 1 to 4 of 4

Please Help With Slow VBA Code

Hybrid View

  1. #1
    Registered User
    Join Date
    12-04-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    1

    Please Help With Slow VBA Code

    All,
    I have some VBA code that is designed to to import data from a different excel file and put the values into the current excel file. The problem is it is very slow to run. Can anyone please look at the code and provide some insight. (I apologize for the length)



    Private Function GetValue(path, file, sheet, ref)
    ' Retrieves a value from a closed workbook
    Dim arg As String
    ' Make sure the file exists
    If Right(path, 1) <> "\" Then path = path & "\"
    If Dir(path & file) = "" Then
    GetValue = "File Not Found"
    Exit Function
    End If
    ' Create the argument
    arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
    Range(ref).Range("A1").Address(, , xlR1C1)
    ' Execute an XLM macro
    GetValue = ExecuteExcel4Macro(arg)
    End Function



    'Ring Projection Data Import for Section "A"


    Sub RingProjectionDataRetrieveA()
    'No cell calculations or screen updates (speed up macro)

    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False

    [BL36] = [BL35]
    [BM36] = [BM35]



    p = [BL36]
    f = [BM36]
    s = "Ring Projection"
    a = "C13"

    [C7] = GetValue(p, f, s, a)
    a = "c14"
    [C8] = GetValue(p, f, s, a)
    a = "c15"
    [C9] = GetValue(p, f, s, a)
    a = "c16"
    [C10] = GetValue(p, f, s, a)
    a = "c17"
    [C11] = GetValue(p, f, s, a)
    a = "c18"
    [C12] = GetValue(p, f, s, a)
    a = "c19"
    [C13] = GetValue(p, f, s, a)
    a = "c20"
    [C14] = GetValue(p, f, s, a)
    a = "c21"
    [C15] = GetValue(p, f, s, a)
    a = "c22"
    [C16] = GetValue(p, f, s, a)
    a = "c23"
    [c17] = GetValue(p, f, s, a)
    a = "c24"
    [c18] = GetValue(p, f, s, a)
    a = "c25"
    [c19] = GetValue(p, f, s, a)
    a = "c26"
    [c20] = GetValue(p, f, s, a)
    a = "c27"
    [c21] = GetValue(p, f, s, a)
    a = "c28"
    [c22] = GetValue(p, f, s, a)
    a = "c29"
    [C23] = GetValue(p, f, s, a)
    a = "c30"
    [C24] = GetValue(p, f, s, a)
    a = "c31"
    [C25] = GetValue(p, f, s, a)
    a = "c32"
    [C26] = GetValue(p, f, s, a)
    a = "c33"
    [c27] = GetValue(p, f, s, a)
    a = "c34"
    [c28] = GetValue(p, f, s, a)
    a = "c35"
    [c29] = GetValue(p, f, s, a)
    a = "c36"
    [c30] = GetValue(p, f, s, a)
    a = "i13"
    [c31] = GetValue(p, f, s, a)
    a = "i14"
    [c32] = GetValue(p, f, s, a)
    a = "i15"
    [c33] = GetValue(p, f, s, a)
    a = "i16"
    [c34] = GetValue(p, f, s, a)
    a = "i17"
    [c35] = GetValue(p, f, s, a)
    a = "i18"
    [C36] = GetValue(p, f, s, a)
    a = "i19"
    [C37] = GetValue(p, f, s, a)
    a = "i20"
    [C38] = GetValue(p, f, s, a)
    a = "i21"
    [C39] = GetValue(p, f, s, a)
    a = "i22"
    [c40] = GetValue(p, f, s, a)
    a = "i23"
    [c41] = GetValue(p, f, s, a)
    a = "i24"
    [c42] = GetValue(p, f, s, a)
    a = "i25"
    [c43] = GetValue(p, f, s, a)
    a = "i26"
    [c44] = GetValue(p, f, s, a)
    a = "i27"
    [c45] = GetValue(p, f, s, a)
    a = "i28"
    [c46] = GetValue(p, f, s, a)
    a = "D13"
    [D7] = GetValue(p, f, s, a)
    a = "D14"
    [D8] = GetValue(p, f, s, a)
    a = "D15"
    [D9] = GetValue(p, f, s, a)
    a = "D16"
    [D10] = GetValue(p, f, s, a)
    a = "D17"
    [D11] = GetValue(p, f, s, a)
    a = "D18"
    [D12] = GetValue(p, f, s, a)
    a = "D19"
    [d13] = GetValue(p, f, s, a)
    a = "D20"
    [D14] = GetValue(p, f, s, a)
    a = "D21"
    [D15] = GetValue(p, f, s, a)
    a = "D22"
    [d16] = GetValue(p, f, s, a)
    a = "D23"
    [d17] = GetValue(p, f, s, a)
    a = "D24"
    [d18] = GetValue(p, f, s, a)
    a = "D25"
    [d19] = GetValue(p, f, s, a)
    a = "D26"
    [d20] = GetValue(p, f, s, a)
    a = "D27"
    [d21] = GetValue(p, f, s, a)
    a = "D28"
    [d22] = GetValue(p, f, s, a)
    a = "D29"
    [d23] = GetValue(p, f, s, a)
    a = "D30"
    [d24] = GetValue(p, f, s, a)
    a = "D31"
    [d25] = GetValue(p, f, s, a)
    a = "D32"
    [d26] = GetValue(p, f, s, a)
    a = "D33"
    [d27] = GetValue(p, f, s, a)
    a = "D34"
    [d28] = GetValue(p, f, s, a)
    a = "D35"
    [d29] = GetValue(p, f, s, a)
    a = "D36"
    [d30] = GetValue(p, f, s, a)
    a = "J13"
    [d31] = GetValue(p, f, s, a)
    a = "J14"
    [d32] = GetValue(p, f, s, a)
    a = "J15"
    [d33] = GetValue(p, f, s, a)
    a = "J16"
    [d34] = GetValue(p, f, s, a)
    a = "J17"
    [d35] = GetValue(p, f, s, a)
    a = "J18"
    [d36] = GetValue(p, f, s, a)
    a = "J19"
    [d37] = GetValue(p, f, s, a)
    a = "J20"
    [d38] = GetValue(p, f, s, a)
    a = "J21"
    [d39] = GetValue(p, f, s, a)
    a = "J22"
    [d40] = GetValue(p, f, s, a)
    a = "J23"
    [d41] = GetValue(p, f, s, a)
    a = "J24"
    [d42] = GetValue(p, f, s, a)
    a = "J25"
    [d43] = GetValue(p, f, s, a)
    a = "J26"
    [d44] = GetValue(p, f, s, a)
    a = "J27"
    [d45] = GetValue(p, f, s, a)
    a = "J28"
    [d46] = GetValue(p, f, s, a)
    a = "E13"
    [E7] = GetValue(p, f, s, a)
    a = "E14"
    [E8] = GetValue(p, f, s, a)
    a = "E15"
    [E9] = GetValue(p, f, s, a)
    a = "E16"
    [E10] = GetValue(p, f, s, a)
    a = "E17"
    [E11] = GetValue(p, f, s, a)
    a = "E18"
    [E12] = GetValue(p, f, s, a)
    a = "E19"
    [E13] = GetValue(p, f, s, a)
    a = "E20"
    [E14] = GetValue(p, f, s, a)
    a = "E21"
    [E15] = GetValue(p, f, s, a)
    a = "E22"
    [e16] = GetValue(p, f, s, a)
    a = "E23"
    [e17] = GetValue(p, f, s, a)
    a = "E24"
    [E18] = GetValue(p, f, s, a)
    a = "E25"
    [e19] = GetValue(p, f, s, a)
    a = "E26"
    [e20] = GetValue(p, f, s, a)
    a = "E27"
    [e21] = GetValue(p, f, s, a)
    a = "E28"
    [E22] = GetValue(p, f, s, a)
    a = "E29"
    [e23] = GetValue(p, f, s, a)
    a = "E30"
    [e24] = GetValue(p, f, s, a)
    a = "E31"
    [e25] = GetValue(p, f, s, a)
    a = "E32"
    [E26] = GetValue(p, f, s, a)
    a = "E33"
    [e27] = GetValue(p, f, s, a)
    a = "E34"
    [e28] = GetValue(p, f, s, a)
    a = "E35"
    [e29] = GetValue(p, f, s, a)
    a = "E36"
    [E30] = GetValue(p, f, s, a)
    a = "K13"
    [e31] = GetValue(p, f, s, a)
    a = "K14"
    [e32] = GetValue(p, f, s, a)
    a = "K15"
    [e33] = GetValue(p, f, s, a)
    a = "K16"
    [E34] = GetValue(p, f, s, a)
    a = "K17"
    [e35] = GetValue(p, f, s, a)
    a = "K18"
    [e36] = GetValue(p, f, s, a)
    a = "K19"
    [e37] = GetValue(p, f, s, a)
    a = "K20"
    [E38] = GetValue(p, f, s, a)
    a = "K21"
    [e39] = GetValue(p, f, s, a)
    a = "K22"
    [e40] = GetValue(p, f, s, a)
    a = "K23"
    [e41] = GetValue(p, f, s, a)
    a = "K24"
    [E42] = GetValue(p, f, s, a)
    a = "K25"
    [e43] = GetValue(p, f, s, a)
    a = "K26"
    [e44] = GetValue(p, f, s, a)
    a = "K27"
    [e45] = GetValue(p, f, s, a)
    a = "K28"
    [E46] = GetValue(p, f, s, a)
    a = "F13"
    [f7] = GetValue(p, f, s, a)
    a = "F14"
    [F8] = GetValue(p, f, s, a)
    a = "F15"
    [F9] = GetValue(p, f, s, a)
    a = "F16"
    [F10] = GetValue(p, f, s, a)
    a = "F17"
    [F11] = GetValue(p, f, s, a)
    a = "F18"
    [F12] = GetValue(p, f, s, a)
    a = "F19"
    [F13] = GetValue(p, f, s, a)
    a = "F20"
    [F14] = GetValue(p, f, s, a)
    a = "F21"
    [F15] = GetValue(p, f, s, a)
    a = "F22"
    [f16] = GetValue(p, f, s, a)
    a = "F23"
    [f17] = GetValue(p, f, s, a)
    a = "F24"
    [f18] = GetValue(p, f, s, a)
    a = "F25"
    [f19] = GetValue(p, f, s, a)
    a = "F26"
    [f20] = GetValue(p, f, s, a)
    a = "F27"
    [f21] = GetValue(p, f, s, a)
    a = "F28"
    [f22] = GetValue(p, f, s, a)
    a = "F29"
    [f23] = GetValue(p, f, s, a)
    a = "F30"
    [f24] = GetValue(p, f, s, a)
    a = "F31"
    [f25] = GetValue(p, f, s, a)
    a = "F32"
    [f26] = GetValue(p, f, s, a)
    a = "F33"
    [f27] = GetValue(p, f, s, a)
    a = "F34"
    [f28] = GetValue(p, f, s, a)
    a = "F35"
    [f29] = GetValue(p, f, s, a)
    a = "F36"
    [f30] = GetValue(p, f, s, a)
    a = "L13"
    [f31] = GetValue(p, f, s, a)
    a = "L14"
    [f32] = GetValue(p, f, s, a)
    a = "L15"
    [f33] = GetValue(p, f, s, a)
    a = "L16"
    [f34] = GetValue(p, f, s, a)
    a = "L17"
    [f35] = GetValue(p, f, s, a)
    a = "L18"
    [f36] = GetValue(p, f, s, a)
    a = "L19"
    [f37] = GetValue(p, f, s, a)
    a = "L20"
    [f38] = GetValue(p, f, s, a)
    a = "L21"
    [f39] = GetValue(p, f, s, a)
    a = "L22"
    [f40] = GetValue(p, f, s, a)
    a = "L23"
    [f41] = GetValue(p, f, s, a)
    a = "L24"
    [f42] = GetValue(p, f, s, a)
    a = "L25"
    [f43] = GetValue(p, f, s, a)
    a = "L26"
    [f44] = GetValue(p, f, s, a)
    a = "L27"
    [f45] = GetValue(p, f, s, a)
    a = "L28"
    [f46] = GetValue(p, f, s, a)


    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

    End Sub

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Please Help With Slow VBA Code

    I noticed you have 2 "Screen Updating" lines, one is set to false, the 2nd is set to true. Not sure, but if you set the 2nd to false, would that help any?

  3. #3
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Please Help With Slow VBA Code

    Scratch previous post, I figured out why there is 2 lines of it

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Please Help With Slow VBA Code

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)


    Are you sure the code is slow and it not just the action of reading from closed files that is slow. What happens if you step through the code line by line, is there a delay on this line

    GetValue = ExecuteExcel4Macro(arg)
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Why is this code so slow?
    By cmmercer in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-25-2014, 06:32 AM
  2. [SOLVED] Vba code makes workboos slow. Any alternate code ??
    By satputenandkumar0 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-23-2014, 04:30 AM
  3. Slow code
    By luizdeh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-21-2011, 01:55 PM
  4. [SOLVED] Better Way To Do This SLOW code
    By rshow1971@frontiernet.net in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-27-2006, 04:30 AM
  5. [SOLVED] Better Way To Do This SLOW code
    By rshow1971@frontiernet.net in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-28-2005, 05:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1