Results 1 to 20 of 80

Thread: Need help gettin this macro to run faster, Please!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #24
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,888
    Location
    Matching 5 is easy and fast

    This seems to work on my test data

    Also assumes that there can be multiple K values for each G value

    Option Explicit
    Sub match_5()
        Dim rG As Range, rK As Range
        Dim G As Long, K As Long, n As Long
        
        Application.ScreenUpdating = False
            
        'setup G's
        Set rG = ActiveSheet.Cells(1, 7)
        Set rG = Range(rG, rG.End(xlDown))
        rG.Interior.ColorIndex = xlColorIndexNone
        
        
        'setup K's
        Set rK = ActiveSheet.Cells(1, 11)
        Set rK = Range(rK, rK.End(xlDown))
        rK.Interior.ColorIndex = xlColorIndexNone
        
        
        For G = 1 To rG.Rows.Count
            
            If G Mod 100 = 0 Then Application.StatusBar = "Processing G row " & Format(G, "#,##0")
            
            Set rK = ActiveSheet.Cells(1, 11)
            Set rK = Range(rK, rK.End(xlDown))
            
            n = 0
            On Error Resume Next
            n = Application.WorksheetFunction.Match(rG.Cells(G, 1), rK, 0)
                    
            Do While n > 0
                rG.Cells(G, 1).Interior.Color = vbRed
                rK.Cells(n, 1).Interior.Color = vbRed
            
                Set rK = rK.Cells(n + 1, 1)
                Set rK = Range(rK, rK.End(xlDown))
                        
                n = 0
                n = Application.WorksheetFunction.Match(rG.Cells(G, 1), rK, 0)
            Loop
            
            On Error GoTo 0
        Next G
        
        Application.StatusBar = False
        
        Application.ScreenUpdating = True
        
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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