+ Reply to Thread
Results 1 to 5 of 5

My Code takes too long to execute

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    My Code takes too long to execute

    Private Sub Worksheet_Change(ByVal Target As Range)
    'Place the word SITE in the Target Cell if it is Blank
    If Not Application.Intersect(Target, Range("B5,B9,B13,E5,E9,E13,H5,H9,H13,K5,K9,K13,N5,N9,N13,Q5,Q9,Q13,T5,T9,T13")) Is Nothing Then
    If Target.Value = "" Then Target.Value = "Site"
    End If
    If Range("K2").Value <> "" Then Range("K2").Value = UCase(Range("K2").Value)
    End Sub
    Is there a faster execution scenario with this?

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    I'd change the order of evaluation as a matter of practice:
    Private Sub Worksheet_Change(ByVal Target As Range)
        Static r As Range
        
        If r Is Nothing Then Set r = Range("B5,B9,B13,E5,E9,E13,H5,H9,H13,K5,K9,K13,N5,N9,N13,Q5,Q9,Q13,T5,T9,T13")
    
        Application.EnableEvents = False
        With Target
            If IsEmpty(.Value) Then
                If Not Application.Intersect(.Cells, r) Is Nothing Then .Value = "Site"
            End If
        End With
        
        With Range("K2")
            If Not IsEmpty(.Value) Then .Value = UCase(.Text)
        End With
    
        Application.EnableEvents = True
    End Sub
    .... but I can't imagine you could tell the difference in the speed of the user interface.
    Last edited by shg; 07-30-2008 at 12:00 AM.

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Hi Coreytroy,

    How long is it taking this to execute on your PC? It's nearly instantaneous on my 3-year-old laptop running XP Pro/Office 2K3.

  4. #4
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494
    It seems to Stall Excel for about 2-3 seconds, and prevents anything from being done.

    I removed the code and i get no stalls.
    But i need it in there.

    What other problem could it be if not the code directly?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Try Stephen Bullen's CodeCleaner. You can find it on the web.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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