从<br>标记中提取
我有以下格式的电子邮件地址,放在Excel 2007中的一列中,如下所示:
<td class="Normal">street name1<br>street name 2<br>city, state zipcode<br>country<br>contact no</TD>
有些单元格有不同的<br>
标签,如下所示:
<td class="Normal">street name 1<br>city, state postal<br>country</TD>
我可以使用Excel“文本到列”function提取最后两个标记,但是在列中提取时转换不一致,并且需要将每列alignment到合适的位置。
该列表都有“,”来区分街道地址,我可以使用“文本到列”function来提取“,”之前的所有数据,然后在第一个子集上获取数据,如下所示:
<td class="Normal">street name1<br>street name 2<br>city
有没有办法从两个第一个<br>
标签或一个脚本之间抽取来计算<br>
标签的数量,然后使用一个脚本来提取不同列中的每一组<br>
标签,标签和其他有两个<br>
标签。
我想这是你在找什么:
Sub Demo() Dim str() As String, tempStr As String Dim lastRow As Long, i As Long, colStart As Long, r As Long lastRow = Cells(Rows.Count, "A").End(xlUp).Row '-->get last row with data For r = 1 To lastRow tempStr = Range("A" & r).Value colStart = 2 str = Split(tempStr, "<br>") '-->split string on tag <br> For i = 1 To UBound(str) - 1 Cells(r, colStart) = str(i) colStart = colStart + 1 Next Next r End Sub
见图像以供参考:
编辑#1:根据我们的讨论进行更改________________________________________________________________________________
Sub Demo() Dim str() As String, tempStr As String Dim lastRow As Long, i As Long, colStart As Long, r As Long lastRow = Cells(Rows.Count, "A").End(xlUp).Row '-->get last row with data For r = 1 To lastRow tempStr = Range("A" & r).Value colStart = 2 str = Split(tempStr, "<br>") '-->split string on tag <br> For i = 1 To UBound(str) If i = UBound(str) Then 'this section will take care of the string with just one <br> tag If UBound(str) = 1 Then Cells(r, colStart) = str(1) End If Else Cells(r, colStart) = str(i) colStart = colStart + 1 End If Next Next r End Sub