2017-03-02 183 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