2017-03-02 172 views
0

我試圖提取從具有式生成鏈路評估下式:提取URL從超鏈接=()

=HYPERLINK("https://www.google.com/search?q="&A1&B1,"Link")
A1具有vbaB1具有help

我已經看到很多很多線索,甚至有一些SO threads的建議,但他們只是讓我到...q=沒有考慮我有更多的文字來。

好運我已經到目前爲止是this thread,我已經調整了其搜索,直到B1這樣的:

... 
S = Left(S, InStr(S, "B17") + 2) 
... 

但它返回https://www.google.com/search?q="&A1&B1

如何在返回URL之前先評估這些單元格中的內容?

+2

您是否嘗試過建立在字符串中的輔助列,看是否有差別?即使只是爲了排除它的公式或數據(如果這是有道理的) –

+0

@MacroMan - ... !!!如果我快速提取'('和第一個逗號之間的文本,我想我可以這樣做,當時我一直在想從公式中提取太久,我想我可以用'Mid ()'。讓我試試看,謝謝你的想法!編輯:等等,嗯。我必須提取它,同時保留引用,並把它放在一個單元格中,以便它可以評估。也許我可以使用'Evaluate )'? – BruceWayne

+0

你也可以用'split()'來解決這個問題,比如'Split(t,Chr(34))(1)&Range(Split(t,「&」)(1))。值和範圍(左(拆分(t,「&」)(2),2))。值 – JNevill

回答

2

我正在過度認爲,我想。感謝@MacroMan讓我的頭腦清晰。我把下面這個非常笨重的宏放在一起。

Function hyperlinkText(rg As Range) As String 
' Inspired by https://stackoverflow.com/questions/32230657/extract-url-from-excel-hyperlink-formula/32233083#32233083 
Dim sFormula As String 
Dim Test As String 

sFormula = rg.Formula 
Test = Mid(sFormula, WorksheetFunction.Search("""", sFormula), WorksheetFunction.Search(",", sFormula) - WorksheetFunction.Search("""", sFormula)) 
hyperlinkText = Evaluate("=" & Test) 
End Function 

這可以採取如下的URL,如:
=HYPERLINK("https://www.google.com/search?q="&A17&B17,"Link")並返回評估網址:

enter image description here