删除Microsoft Excel中特定标记之间的文本 [英] Remove text between specific tags in Microsoft Excel
问题描述
Lorem ipsum dolor< code> sit amet,consectetuer adipiscing elit, /代码> sed diam nonummy nibh euismod tincidunt ut< code> laoreet dolore magna< / code> aliquam erat volutpat。
我正在尝试删除每对代码标签之间的所有内容。当每个单元格只有一对标签时,我写了一个功能很好的功能,但它并不适用于多个实例。以下是所需的输出:
Lorem ipsum dolor< code>< / code> sed diam nonummy nibh euismod tincidunt ut< code>< / code>你要建议我做什么?
解决方案基于宏记录器:
Sub Test()
'working for选择替换所有< *> section
Selection.Replace What:=&* *>,Replacement:=,LookAt:= xlPart,_
SearchOrder:= xlByRows,MatchCase:= False,SearchFormat:= False, _
ReplaceFormat:= False
End Sub
编辑尝试2,在OP的评论之后:
Sub Attempt_second()
'用于选择替换所有< * GT; section
Selection.Replace what:=< * code> *< * / * code>,替换:=< code>< / code>,LookAt:= xlPart,_
SearchOrder:= xlByRows,MatchCase:= False,SearchFormat:= False,_
ReplaceFormat:= False
End Sub
它会将文本替换为
< code>< / code>
删除其间的其他空格。I have some text that goes like this:
Lorem ipsum dolor <code>sit amet, consectetuer adipiscing elit,</code> sed diam nonummy nibh euismod tincidunt ut <code>laoreet dolore magna</code> aliquam erat volutpat.
I am trying to remove everything between each pair of "code" tags. I wrote a function that works well when there is only one pair of tags per cell, but it doesn't take care of multiple instances. Here is the desired output:
Lorem ipsum dolor <code></code> sed diam nonummy nibh euismod tincidunt ut <code></code> aliquam erat volutpat.
How would you advise me to do?
解决方案Based on macro recorder:
Sub Test() 'working for selection replacing all <*> sections Selection.Replace What:="<*>", Replacement:="", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False End Sub
Edit attempt 2, after comments from OP:
Sub Attempt_second() 'working for selection replacing all <*> sections Selection.Replace What:="<*code>*<*/*code>", Replacement:="<code></code>", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False End Sub
It will replace text into
<code></code>
removing additional spaces in between.这篇关于删除Microsoft Excel中特定标记之间的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!