Я тут пока написал немного другой код, загнал второй спискок в массив, но при использовании .Find выдаёт ошибку Type mismatch. Где я накосячил?
Код |
---|
Sub FindMultipleOccurrences() ''''''''Get the request name GetBook = ActiveWorkbook.Name ''''''''Take BlackListMaterials Workbooks("BB_Cleaner_Macros_V4.xlsm").Activate Dim myArray As Variant myArray = Range("A2:C609") ''''''''Back to request Workbooks(GetBook).Activate For R = 1 To 609 Dim LookFor As String LookFor = CStr(myArray(R, 1)) ''''''''Look in BB part 'finding multiple occurrences of a value in a range Dim rngSearch As Range, rngLast As Range, rngFound As Range Dim strFirstAddress As String 'set the search range: Set rngSearch = ActiveSheet.Range("B:B") 'specify last cell in range: Set rngLast = rngSearch.Cells(rngSearch.Cells.Count) 'Find the string from Array in search range, when it first occurrs. Note that the After argument is used to begin search after the last cell in the search range. Set rngFound = rngSearch.Find(What:=LookFor, After:=ActiveCell, LookIn:=xlValues, LookAt:= _ xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _ False, SearchFormat:=False) 'if Array value is found in search range: If Not rngFound Is Nothing Then 'saves the address of the first occurrence of value, in the strFirstAddress variable: strFirstAddress = rngFound.Address Do 'Find next occurrence of value. Note, that we do not start from the first occurrence of value (ie. strFirstAddress). Set rngFound = rngSearch.FindNext(rngFound) 'replace value with "Deleted": rngFound.Value = "Deleted!" Loop Until rngFound.Address = strFirstAddress End If ''''''''Loop to next Array value Next R End Sub |