Results 1 to 4 of 4

Code running v slowly when Called from another Macro

Threaded View

  1. #1
    Registered User
    Join Date
    03-03-2008
    Posts
    4

    Code running v slowly when Called from another Macro

    Hi there, I'm creating a game in excel - I'm pretty new to vba code writing and have come across a problem that has me stumped...

    I have some code as follows which takes approx. 30 seconds to run (ALLENEMYMOVE). However when I Call this at the end of another macro (AFTERFIGHTTOHOME) the same code now takes approx 5 mins to run. The cells altered by the (AFTERFIGHTTOHOME) macro do not affect the (ALLENEMYMOVE) macro so not sure what the difference is - if I run the two parts of code separately they execute quickly but putting them together seems to decrease the speed substantially. Any ideas why this is or how to get round this? Many thanks,

    Theo


    Sub ALLENEMYMOVE()
    
    ' ALLENEMYMOVE Macro
    '
    'Zap location of home armies
    EnableEvents = False
    Call ACTIVEROWCOLUMN3
    Sheets("Map").CALCULATE
    Dim No_of_Times_to_Repeat As Integer
    Dim i As Integer
    No_of_Times_to_Repeat = Sheets("Arena").Range("CN2").Value
    'No_of_Times_to_Repeat = 1
    For i = 1 To No_of_Times_to_Repeat
    'Choose next army
    If Sheets("Arena").Range("CO" & (i + 6)).Value <> "X" Then
    Sheets("Arena").Range("CM5").Value = Sheets("Arena").Range("CM" & (i + 6)).Value
    Sheets("Arena").Range("DL5").Value = Sheets("Arena").Range("DL4").Value
    Sheets("Arena").CALCULATE
    Call ENEMYMOVE
    End If
    Next i
    Range("A1").Select
    EnableEvents = True
    End Sub
    
    
    
    Sub AFTERFIGHTTOHOME()
    '
    ' AFTERFIGHTTOHOME Macro
    
        Sheets("Home").Range("C2:H16").Value = Sheets("Home").Range("CD2:CI16").Value
        Sheets("Home").Range("BF2:BK16").Value = Sheets("Home").Range("CJ2:CO16").Value
        Sheets("Home").Range("BN2:BN16").Value = Sheets("Home").Range("CP2:CP16").Value
        Sheets("Map").Select
        Range("A1").Select
        Range("CH36") = 0
        CALCULATE
        Call ALLENEMYMOVE
    
    End Sub
    Last edited by theo499; 02-04-2019 at 05:54 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help my code is running very slowly..
    By wishmaker in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-06-2014, 06:03 AM
  2. VBA Code is running really slowly
    By behrensf84 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-07-2014, 06:06 PM
  3. Code running really slowly
    By The Phil in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-03-2014, 08:42 PM
  4. [SOLVED] Code running slowly
    By Sweepin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-30-2013, 09:15 PM
  5. [SOLVED] Code running slowly any way of speeding up processing time
    By boomboomblock in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-02-2013, 09:09 AM
  6. Code running slowly
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 02-01-2011, 11:08 AM
  7. Paste code running extremely slowly...
    By KR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-03-2005, 11:05 AM

Tags for this Thread

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