我有一张Excel工作表,其中有一个“说明”列。此列中的值通常包含0-3个标记,全部以#符号开头。有没有办法将所有这些标签拉入列?
也许只有3个空白列名为#1,2,3,并将它们拉入每一列。
将它们拉出时,从描述栏中删除它们并不重要。
描述示例:
"#0034 #lost client lost file" - pull out 0034 and lost "worker has bad quality #SusanB #quality" - pull out SusanB and quality "#0840 client complaint" - pull out 0840 "lots of ipsum" - pull out nothing
答案 0 :(得分:2)
让我们说列A是描述列,而在A2中你有第一个带有主题标签的单元格 在B2中输入:
=MID(A2;(FIND("#";A2))+1;(FIND(" ";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))-(FIND("#";A2))-1)
在C2中输入:
=MID(A2;(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))+1;(FIND(" ";MID(A2;(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))+1;LEN(A2)-(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))))+(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2))))-(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))-1)
在D2中输入:
=MID(A2;(FIND("#";MID(A2;(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))+1;LEN(A2)-(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))))+(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2))))+1;(FIND(" ";MID(A2;(FIND("#";MID(A2;(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))+1;LEN(A2)-(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))))+(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2))))+1;LEN(A2)-(FIND("#";MID(A2;(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))+1;LEN(A2)-(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))))+(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2))))))+(FIND("#";MID(A2;(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))+1;LEN(A2)-(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))))+(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))))-(FIND("#";MID(A2;(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))+1;LEN(A2)-(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2)))))+(FIND("#";MID(A2;(FIND("#";A2))+1;LEN(A2)-(FIND("#";A2))))+(FIND("#";A2))))-1)
答案 1 :(得分:1)
我喜欢可以让你在Excel中使用REGEX的扩展程序......
没有这个:
1)使用FIND()
在字符串中查找分隔符(#?)的位置2)然后使用LEFT(),MID()和RIGHT()将你的字符串分成3列
3)你可以删除#使用MID()而不是LEFT()和RIGHT()
-
第一个带#:
的标签会是这样的= LEFT(A1,FIND( “#”,A1)-1)
-
希望这会有所帮助!
答案 2 :(得分:0)
这总是可以使用正则表达式完成。
在VBE中,在模块中编写以下函数:
Function getHashTags(rng As Range) As Variant
Dim regEx As RegExp
Set regEx = New RegExp
regEx.Pattern = "#\w*\b"
regEx.IgnoreCase = True
regEx.Global = True
Set myMatches = regEx.Execute(rng.Value)
Dim arr(1 To 1, 1 To 3) As Variant
For i = 1 To 3
If i > myMatches.Count Then
arr(1, i) = ""
Else
arr(1, i) = Replace(myMatches(i - 1), "#", "")
End If
Next i
getHashTags = arr
End Function
现在,我们假设列A是Description列,而在单元格A2中,您有第一个带有哈希标记的单元格。
在单元格B2中输入:
=getHashTags(B$2)
现在选择单元格B2,C2,D2,按 F2 然后 ctrl + shift + 输入 。这将填充从函数getHashTags
到选定单元格的变量返回。
我希望这会有所帮助。
PS:并且,是的,为此,您还需要参考 Microsoft VBScript Regular Expressions 5.5 库。