簡體   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