简体   繁体   English

Excel在公式中查找和替换文本

[英]Excel Find And Replace Text in Formula

I have 3 columns: A and B contain numbers, and C has a html link. 我有3列:A和B包含数字,C具有html链接。 I want to replace numbers in the html link with the numbers from columns A & B. 我想用A列和B列中的数字替换html链接中的数字。

Can anyone tell me how I can do this? 谁能告诉我该怎么做? I tried using the replace function, but it doesnt work for multiple variables. 我尝试使用replace函数,但不适用于多个变量。

Example: random.com/do?ID=1111&SourceID=2222 I'd replace 1111 with ID columan A 617 and 2222 with sourceID column B 2 例如:random.com/do?ID=1111&SourceID=2222我将1111替换为ID columan A 617,将2222替换为sourceID列B 2

SourceID LocationID link
617     2           random.com/do?ID=1111&SourceID=2222 
1878     39         random.com/do?ID=1111&SourceID=2222  
4148     48         random.com/do?ID=1111&SourceID=2222

I would not use the replace formula here because it requires a "position and length" which will change once you update the link with a new value from SourceID or LocationID and the logic to figure out the new location is overkill and not needed. 不会在这里使用replace公式,因为它需要一个“位置和长度”,一旦您使用SourceID或LocationID中的新值更新链接,该值就会更改,并且弄清楚新位置的逻辑是多余的,因此不需要。

Instead you can use the Substitute formula instead which I think is more readable and easier to implement. 相反,您可以改用Substitute公式,我认为该公式更易读和易于实现。 This formula replaces "text" with "text" 该公式将“文本”替换为“文本”

If you use 2 Substitutes (1 outer and 1 nested) you can replace both strings in one line. 如果使用2个Substitutes (1个外部和1个嵌套),则可以在一行中替换两个字符串。 Try putting this in column D 尝试将其放在D列中

=SUBSTITUTE(SUBSTITUTE(C1,"1111",A1),"2222",B1)

and you can auto-fill down 您可以自动填写

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

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