Results 1 to 6 of 6

how to optimize finding matching values macro speed

Threaded View

  1. #1
    Forum Contributor
    Join Date
    08-08-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    196

    how to optimize finding matching values macro speed

    Dear all,

    I am writing to seek help in optimizing the following macro below, as is freezes and displays the out put after 10/15 minutes.

    I have posted a same thread on the following forum below but did not get any response:

    http://www.mrexcel.com/forum/excel-q...tch-value.html

    Option Explicit
    Sub FindNamesV3()
    
    Dim g As Variant
    Dim lr1 As Long, lr2 As Long, i As Long, fb As Long, fc As Long
    Application.ScreenUpdating = False
    lr1 = Sheets("Sheet1").Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row + 1
    With Sheets("Sheet2")
      .Columns("I:I").ClearContents
      lr2 = .Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row + 1
      g = .Range("G1:I" & lr2)
      For i = 1 To UBound(g, 1)
        If g(i, 1) = "" And g(i, 2) = "" Then
          'do nothing
        ElseIf g(i, 1) <> "" And g(i, 2) = "" Then
          fb = 0
          On Error Resume Next
          fb = Application.Match(g(i, 1), Sheets("Sheet1").Range("B1:B" & lr1), 0)
          On Error GoTo 0
          If fb > 0 Then
            g(i, 3) = Sheets("Sheet1").Range("A" & fb).Value
          End If
        ElseIf g(i, 1) = "" And g(i, 2) <> "" Then
          fc = 0
          On Error Resume Next
          fc = Application.Match(g(i, 2), Sheets("Sheet1").Range("C1:C" & lr1), 0)
          On Error GoTo 0
          If fc > 0 Then
            g(i, 3) = Sheets("Sheet1").Range("A" & fc).Value
          End If
        ElseIf g(i, 1) <> "" And g(i, 2) <> "" Then
          fb = 0
          On Error Resume Next
          fb = Application.Match(g(i, 1), Sheets("Sheet1").Range("B1:B" & lr1), 0)
          On Error GoTo 0
          If fb > 0 Then
            g(i, 3) = Sheets("Sheet1").Range("A" & fb).Value
          End If
          fc = 0
          On Error Resume Next
          fc = Application.Match(g(i, 2), Sheets("Sheet1").Range("C1:C" & lr1), 0)
          On Error GoTo 0
          If fc > 0 Then
            g(i, 3) = Sheets("Sheet1").Range("A" & fc).Value
          End If
        End If
      Next i
      .Range("G1:I" & lr2) = g
      .Columns(9).AutoFit
      Erase g
      .Activate
    End With
    Application.ScreenUpdating = True
    MsgBox "Sheet2 column I returned " & Application.CountA(Sheets("Sheet2").Columns("I:I")) & " names from Sheet1 column A."
    End Sub

    Thank you for your time and help.
    Last edited by missy22; 09-25-2013 at 10:45 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Finding matching values from different columns
    By hefe_espada in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-23-2013, 07:24 PM
  2. [SOLVED] Finding Duplicate and Matching Values in Rows
    By fitkhan in forum Excel General
    Replies: 2
    Last Post: 04-05-2012, 09:07 PM
  3. Finding the Lowest Values and Matching
    By artiststevens in forum Excel General
    Replies: 1
    Last Post: 05-04-2011, 11:45 PM
  4. Replies: 1
    Last Post: 04-02-2011, 06:39 AM
  5. Finding Matching values in cells
    By Zemmy in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-26-2008, 04:09 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