Closed Thread
Results 1 to 2 of 2

Efficiency… Efficiency… Efficiency…

Hybrid View

  1. #1
    Registered User
    Join Date
    04-05-2009
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    44

    Smile Efficiency… Efficiency… Efficiency…

    Hi All,

    Is there any way to bring more efficiency in this code.
    I need to run this code on 100,000 rows every week and this takes hours to finish.

    Can someone make this run faster please. You can see the attachment.
    Thanks...



    Option Explicit
    Sub Find_Offset()
    
        Dim T As Date
        Dim I As Long
        Dim J As Long
        Dim X As Long
        Dim R As Long
        Dim A As Double
        Dim B As Double
                 
        T = Now()
        I = 0
        J = 1
        X = 1
        R = Range(Selection, Selection.End(xlDown)).Rows.Count
        
        Application.ScreenUpdating = False
        
        With ActiveCell
            .Offset(0, 1).Columns("A:A").EntireColumn.Insert Shift:=xlToRight
            .Offset(-1, 1).Value = "Offsetting Pairs"
        End With
        
        For I = 0 To R - 2
            If IsEmpty(ActiveCell.Offset(I, 1)) Then
                A = ActiveCell.Offset(I, 0).Value
                For J = I + 1 To R - 1
                    If IsEmpty(ActiveCell.Offset(J, 1)) Then
                        B = ActiveCell.Offset(J, 0).Value
                        If A + B = 0 Then
                            With ActiveCell
                                .Offset(I, 1).Value = X
                                .Offset(J, 1).Value = X
                            End With
                            X = X + 1
                            Exit For
                        End If
                    End If
                Next
            End If
        Next
           
        MsgBox (X - 1) * 2 & " Offsetting values and " & R - ((X - 1) * 2) & _
                " Net values found in the range." & vbNewLine & _
                "Total time taken by this code to analyze is " & _
                Format((Now() - T) * 86400, "0.00") & " seconds."
       
        Application.ScreenUpdating = True
    
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Efficiency… Efficiency… Efficiency…

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

Closed Thread

Thread Information

Users Browsing this Thread

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

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