我想根据查找表对单元格内的多个字符串进行替换。
我的查阅表有两列:
AUSTRIA | AT
BRAZIL | BR
COLOMBIA| CO
我的数据表有两列:
Apples | AUSTRIA,COLOMBIA
Banana | BRAZIL,AUSTRIA
我希望数据表中的值能够被查找表中的值替换(由于每个 ISO 国家代码都很长)。
期望输出:
Apples | AT,CO
Banana | BR,AT
有什么想法吗?最好避免使用 VBA!
答案1
如果您决定这样做(速度会很快,就像撕掉创可贴一样),这里有一个 VBA 解决方案。只需进行注释中指出的必要更改,即可使其适用于您的工作簿。
Sub abbrev()
Dim abvtab() As Variant
Dim ltsheet As Worksheet
Dim datasheet As Worksheet
Dim lt As Range
'Change Lookup to the sheet name with your lookup table.
Set ltsheet = Sheets("Lookup")
'Change Data to the sheet name with your data.
Set datasheet = Sheets("Data")
'Change A2 to the top left cell (not the header) in your lookup table.
'Change B2 to top right cell.
Set lt = ltsheet.Range("A2", ltsheet.Range("B2").End(xlDown))
abvtab = lt
For i = 1 To UBound(abvtab)
datasheet.Cells.Replace What:=abvtab(i, 1), Replacement:=abvtab(i, 2), LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False
Next i
End Sub