I have Sheet1 with 55 thousand rows and in another worksheet I have a named range consisting of a single column containing 450 values. Since the cells in F to H may contain multiple words in a cell, currently I'm searching for partial word matches and if I find any one of the 450 values in any cell in F, G or H I put "delete" in column X. My macro as written takes 7 minutes to run. I could post my macro but what I'm looking for is an example of a very fast method that might cut the time down to less than a minute.
I found this method on-line and it claims to be the fastest way to do something like I want to do but I'm not smart enough to convert it for my situation.
Code:'**************************************************** 'Purpose: Search a range and return an array showing the row 'and column location of the target value. 'rngSearch - specify the range to search 'strTarget - specify the value to search for '**************************************************** Function Func_Search_Range_With_MATCH( _ ByRef rngSearch As Range, _ ByVal strTarget As String _ ) As Variant 'declare variables Dim arrOutput As Variant 'specify output array (row found, col found) 'set output array to not found as default ReDim arrOutput(1 To 1, 1 To 2) 'create output array arrOutput(1, 1) = -1 'set default to -1 arrOutput(1, 2) = -1 'set default to -1 'determine size of search range Dim lgRowSize As Long Dim lgColSize As Long lgRowSize = rngSearch.Rows.Count lgColSize = rngSearch.Columns.Count 'break the search range into a "strip" of continguous cells by row or column depending which is smaller or optimise speed 'search each strip using MATCH Dim rngStrip As Range 'declare a "strip" of cells Dim lgStripCounter As Long 'declare a "strip" counter Dim vntRelativeLocation As Variant 'specify the relative location of found target within the "strip" Dim lgAbsoluteStartLocation As Long 'absolute start column no: or row no: of a "strip" On Error Resume Next If lgColSize < lgRowSize Then 'smaller no: of columns 'search by columns For lgStripCounter = 1 To lgColSize lgAbsoluteStartLocation = rngSearch.Columns(lgStripCounter).Cells(1, 1).Column 'determine the start location of the first cell in strip vntRelativeLocation = Application.WorksheetFunction.Match(strTarget, rngSearch.Columns(lgStripCounter), 0) 'search the target using MATCH in the strip If Err.Number = 0 Then 'determine the results arrOutput(1, 1) = vntRelativeLocation + lgAbsoluteStartLocation - 1 'found row location arrOutput(1, 2) = lgStripCounter 'found column location Exit For Else Err.Clear End If Next Else 'smaller no: of rows or equal rows and columns For lgStripCounter = 1 To lgRowSize lgAbsoluteStartLocation = rngSearch.Rows(lgStripCounter).Cells(1, 1).Row 'determine the start location of the first cell in strip vntRelativeLocation = Application.WorksheetFunction.Match(strTarget, rngSearch.Rows(lgStripCounter), 0) 'search the target using MATCH in the strip If Err.Number = 0 Then 'determine the results arrOutput(1, 1) = vntRelativeLocation + lgAbsoluteStartLocation - 1 'found row location arrOutput(1, 2) = vntRelativeLocation 'found column location Exit For Else Err.Clear End If Next End If 'output the result Func_Search_Range_With_MATCH = arrOutput End Function




Reply With Quote