Excel 如何删除单元格中除特定 html 标记中的内容以外的所有内容?

Excel How I can delete everything in a cell except the content within specific html tag?

我的 Excel sheet 有超过 700 行,在第二列中我有 html 代码中的产品描述。我需要提取始终在 ....

中的特定值
<div class="something">
   <p><strong>Content to remove</strong></p>
   <h1>Content to remove</h1>
   <p>Content to remove</p>
   <h1 class="modelaut">CONTENT TO KEEP</h1>
   <p>Content to remove</p>...
</div>

"CONTENT TO KEEP" 在每一行中的位置不同,但总是在具有特定 class="modelaut"

的 H1 标签中

感谢您的帮助:)

单元格 A1:

hfewyuifgd<h1876yhfr4>TREASURE</h1vnc>xv67t4gehsd

这个公式:

=LEFT(MID(A1,FIND(">",A1,FIND("<h1",A1))+1,99990),FIND("<",MID(A1,FIND(">",A1,FIND("<h1",A1))+1,99990))-1)

将return:

宝藏

代码应该是这样的。

Sub transString()
    Dim vDB, vSplit1, vSplit2
    Dim rngDB As Range, i As Long
    Set rngDB = Range("b1", Range("b" & Rows.Count).End(xlUp))
    vDB = rngDB
    For i = 1 To UBound(vDB, 1)
        vSplit1 = Split(vDB(i, 1), "<h1 class=" & Chr(34) & "modelaut" & Chr(34) & ">")
        vSplit2 = Split(vSplit1(1), "</h1>")
        vDB(i, 1) = "<h1 class=" & Chr(34) & "modelaut" & Chr(34) & ">" & vSplit2(0) & "</h1>"
    Next i
    rngDB = vDB
End Sub

以下公式适用于所写的数据和问题:

=MID(C1,FIND(">",C1,FIND("<h1 class",C1)+1)+1,FIND("</h1",C1,FIND("<h1 class",C1)+1)-FIND(">",C1,FIND("<h1 class",C1)+1)-1)