你的意思是A列和C列不在同一张工作表中吗? 假设A列在Sheet1中,C列在Sheet2中, Sub 精准替换() '采用单元格匹配的模式替换,不会替换掉包含关系的数据 Sheet2.Range(C:C).Replace What:=Sheet1.Range(A1), Replacement:=Y, LookAt:=xlWhole End Sub
Function BREPLACE(ByVal text As String, ByVal datarange As Variant, Optional ByVal Delimiter As String = ) As String Dim arr As Variant, data As Variant If IsArray(datarange) Then data = datarange Else data = datarange.Value End If Set dic = CreateObject(scripting.dictionary) For i = LBound(data, 1) To UBound(data, 1) If Not dic.exists(data(i, 1) & ) Then dic.Add data(i, 1) & , data(i, 2) End If Next arr = Split(text, Delimiter) If IsArray(arr) Then For i = 0 To UBound(arr) arr(i) = dic.Item(arr(i)) Next BREPLACE = Join(arr, Delimiter) Else BREPLACE = dic.Item(text) End If End Function