用替代词replace许多单词

我想用替代标签(或单词)replace很多单词。 每个单词都有一个特定的标签,但要花费很多时间才能find和replace。

任何配方可以帮助这种情况?

我有三栏:

  1. 第一列有我要replace的字句
  2. 第二列有我想要replace的所有词
  3. 在第三栏旁边是replace字或新标签。

+---+-------------------------+----------------------------+---------------------------+ | | A | B | C | +---+-------------------------+----------------------------+---------------------------+ | 1 | sentence word1 sentence |          word3   |            tag3 | | 2 | sentence word2 sentence |                 word6     |                      tag6 | | 3 | sentence word3 sentence |                 word8     |                      tag8 | | 4 | sentence word4 sentence |                word9     |                      tag9 | | 5 | sentence word5 sentence |                 word10    |                     tag10 | +---+-------------------------+----------------------------+---------------------------+ 

一个UDF做的伎俩

在调查了=substitute()数组forms的=substitute()之后,我决定了一个UDF。 将以下代码粘贴到您需要完成的工作簿中的新模块中。

在Excel中,您可以使用该function作为任何其他function。 =FindReplace( :按Ctrl-Shift-a,它会问你的标准。

例如: =FindReplace(A1,$B$1:$B$2,$C$1:$C$2)

  Function FindReplace(Cell As Range, Old_Text As Range, New_Text As Range) As String Dim i As Long, text As String, Old_T() As Variant, New_T() As Variant FindReplace = Cell.Value Old_T = Old_Text.Value New_T = New_Text.Value For i = LBound(Old_T) To UBound(Old_T) FindReplace = Replace(FindReplace, Old_T(i, 1), New_T(i, 1), 1) Next i End Function 

你可以使用下面的UDF

 Function SubstituteMultiple(str As String, old_txt_rng As Range, new_txt_rng As Range) Dim i As Single For i = 1 To old_txt_rng.Cells.Count Result = Replace(LCase(str), LCase(old_txt_rng.Cells(i)), LCase(new_txt_rng.Cells(i))) str = Result Next i SubstituteMultiple = Result End Function 

根据下面的图片在Cell D2中input=SubstituteMultiple(A2,$B$2:$B$6,$C$2:$C$6) ,然后拖拽/复制下来。

在这里输入图像说明

从这里得到这个。