E.g A cell containing "app" or "apple69" should be cleared; but they are getting matched to "apple"
This macro was posted by another user in a different forum and they will not reply. How can the match creteria be made Exact.
This macro was posted by another user in a different forum and they will not reply. How can the match creteria be made Exact.
Code:
Option Explicit
Sub REMOVEINV()
Dim LastRowD As Long
Dim LastRowF As Long
Dim LastColF As Long
Dim key As Variant
Dim i As Long
Dim j As Long
Dim MyDict As Object
Dim SearchRng As Range
Dim TempArr() As Variant
Dim ws As Worksheet
'set objects
Set MyDict = CreateObject("scripting.dictionary")
Set ws = ActiveSheet
'set range bounds
With ws
LastRowD = .Cells(.Rows.Count, "D").End(xlUp).Row
LastRowF = .Cells(.Rows.Count, "F").End(xlUp).Row
LastColF = .Cells(LastRowF, .Columns.Count).End(xlToLeft).Column
Set SearchRng = .Range(.Cells(2, 6), .Cells(LastRowF, LastColF))
End With
'set dictionary
With MyDict
.CompareMode = vbTextCompare
For i = 2 To LastRowD
key = Cells(i, 4).Value
If Not key = vbNullString And Not .exists(key) Then
.Add key, i
End If
Next i
End With
'fetch range data
TempArr = SearchRng.Value
'remove unwanted entries
For i = LBound(TempArr, 1) To UBound(TempArr, 1)
For j = LBound(TempArr, 2) To UBound(TempArr, 2)
If Not TempArr(i, j) = vbNullString Then
If Not MyDict.exists(TempArr(i, j)) Then TempArr(i, j) = vbNullString
End If
Next j
Next i
'plot array
SearchRng = TempArr
Set MyDict = Nothing
End Sub
Last edited by a moderator: