繁体   English   中英

将所有@mentions和#hashtags从A列复制到Excel中的B和C列

[英]Copying all @mentions and #hashtags from column A to Columns B and C in Excel

我有一个很大的推文数据库。 大多数推文都有多个#hashtags和@mentions。 我希望所有#hashtags在一列中用空格分隔,而所有@mentions在另一列中。 我已经知道如何提取的第一次出现#hashtag@mention 但是我不知道全部得到吗? 其中一些推文最多包含8个#hashtags。 手动浏览这些推文并复制/粘贴#hashtags和@mentions对于5,000多个推文来说似乎是不可能的任务。

这是我想要的示例。 我有A列,我想要一个可以填充B列和C列的宏。(我在Windows和Excel 2010中)

Column A
-----------
Dear #DavidStern, @spurs put a quality team on the floor and should have beat the @heat. Leave #Pop alone. #Spurs a classy organization.
Live broadcast from @Nacho_xtreme: "Papelucho Radio"http://mixlr.com nachoxtreme-radio … #mixlr #pop #dance
"Since You Left" by @EmilNow now playing on KGUP 106.5FM. Listen now on http://www.kgup1065.com  #Pop #Rock
Family Night #battleofthegenerations Dad has the #Monkeys Mom has #DonnieOsman @michaelbuble for me #Dubstep for the boys#Pop for sissy
@McKinzeepowell @m0ore21 I love that the PNW and the Midwest are on the same page!! #Pop

我希望列B看起来像这样:

Column B
--------
#DavidStern #Pop #Spurs
#mixlr #pop #dance
#Pop #Rock
#battleofthegenerations #Monkeys #DonnieOsman #Dubstep #Pop
#pop

C列看起来像这样:

Column C:
----------
@spurs @heat
@Nacho_xtreme
@EmilNow
@michaelbuble
@McKinzeepowell @m0ore21

考虑使用正则表达式。

通过从Tools -> References添加对Microsoft VBScript Regular Expressions 5.5的引用,可以在VBA中使用正则表达式。

是一个很好的起点,其中包含许多有用的链接。


更新

添加对Regular Expressions库的引用后,将以下函数放入VBA模块中:

 Public Function JoinMatches(text As String, start As String) Dim re As New RegExp, matches As MatchCollection, match As match re.pattern = start & "\\w*" re.Global = True Set matches = re.Execute(text) For Each match In matches JoinMatches = JoinMatches & " " & match.Value Next JoinMatches = Mid(JoinMatches, 2) End Function 

然后,在单元格B1输入以下公式(用于#标签):

 =JoinMatches(A1,"#") 

C1列中输入以下公式:

 =JoinMatches(A1,"@") 

现在,您可以一直复制公式。

您可以使用其他字符@将文本转换为列,然后对#进行转换,然后将文本的其余部分重新合并为A列,如果您不熟悉正则表达式,请参见(@ Zev-Spitz)

暂无
暂无

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

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