简体   繁体   English

替换单元格中的多个单词

[英]Replace multiple words within a cell

I have multiple cells in a spreadsheet which lists two character country ISO codes in a single cell like so: 我在电子表格中有多个单元格,该电子表格在一个单元格中列出了两个字符所在国家/地区的ISO代码,如下所示:

CA, MX, US

CA, MX, US

CA, CR, MX, US

AD, AE, AR, AT, AU, BD, BE, BG, BO, BR, CH, CI, CL

CA, MX, US

GB, US

I have another sheet which lists the ISO code and full country name. 我还有一张纸列出了ISO代码和完整的国家/地区名称。

I'd like to replace the ISO codes with the full country names. 我想将ISO代码替换为完整的国家/地区名称。

Does anyone have any suggestion of how I can go about this? 有人对我该如何做有什么建议吗?

you can try with VBA as follows (you should back up your file in case of rasing any issue) 您可以按以下方式尝试使用VBA(如果出现任何问题,则应备份文件)
1. Press Alt + F11 to open VBA 1.按Alt + F11打开VBA
2. pass the code as follows 2.通过如下代码

Sub Multi_FindReplace()
Dim sht As Worksheet
Dim fndList As Variant
Dim rplcList As Variant
Dim x As Long

fndList = Array("CA", "MX", "US")
rplcList = Array("canada", "mexico", "usa")

'Loop through each item in Array lists
  For x = LBound(fndList) To UBound(fndList)
    'Loop through each worksheet in ActiveWorkbook
      For Each sht In ActiveWorkbook.Worksheets
        sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _
          LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
          SearchFormat:=False, ReplaceFormat:=False
      Next sht

  Next x

End Sub

3. Save as xlsm 3.另存为xlsm
4. Run the command (in VBA, press F5) 5. Done Notes: 4.运行命令(在VBA中,按F5键)。5.完成注意:

fndList = Array("CA", "MX", "US")
rplcList = Array("canada", "mexico", "usa")

You have to add all the ISO and contries here (using Vlooup and "Concatenate" function for quickly process to generate this string) For your reference: http://www.thespreadsheetguru.com/the-code-vault/2014/4/14/find-and-replace-all 您必须在此处添加所有ISO和contries(使用Vlooup和“ Concatenate”函数可快速处理以生成此字符串)供参考: http : //www.thespreadsheetguru.com/the-code-vault/2014/4/ 14 /查找并替换所有

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM