本文介绍了用替代词替换每个词中的许多词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用替代标签(或单词)替换许多单词.每个单词都有一个特定的标签,但是查找和替换将花费大量时间.

I want to replace many words with alternative Tags(or words). Every word has a specific tag but it will take so much time to do it with find and replace.

任何公式都可以帮助解决这种情况吗?

Can any formula help with this situation?

我有三列:

  1. 第一列的句子中有我要替换的单词
  2. 第二列包含我要替换的所有单词
  3. 第三列旁边的替换词或新标签.


+---+-------------------------+----------------------------+---------------------------+
|   |            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()之后,我选择了UDF.将以下代码粘贴到工作簿中需要完成的新模块中.

A UDF does the trick

After investigating =substitute() in the array form I settled on a UDF. Paste the following code into a new module in the workbook you need this done in.

在excel中,您可以将该函数用作任何其他函数. =FindReplace(:按ctrl-shift-a,它将要求您提供条件.

In excel you can use the function as any other function. =FindReplace( : hit ctrl-shift-a and it will ask you for the criteria.

示例:=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

这篇关于用替代词替换每个词中的许多词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:50