• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 69
  • Last Modified:

Excel Field with URL

I Inherited a XLS file with a column that is a field of values that are hyperlinked, is there a way for me to create another column and extract the actual URL from the hyperlink as a text field?  THe column is C
1
Matt Pinkston
Asked:
Matt Pinkston
  • 10
  • 6
  • 5
2 Solutions
 
Matt PinkstonAuthor Commented:
tried this but got an error

=MID(FORMULATEXT(C2);FIND(CHAR(34);FORMULATEXT(C2))+1;FIND(CHAR(34);FORMULATEXT(C2);FIND(CHAR(34);FORMULATEXT(C2))+1)-1-FIND(CHAR(34);FORMULATEXT(C2)))
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may use UDF to get the url from the hyperlink formula...
Please follow these steps...

1) Open your workbook.

2) Press Alt+F11 to open the VB Editor

3) On VB Editor --> Insertr --> Module and paste the function given below into the opened code window.

4) Close VB Editor and save your workbook as macro enabled workbook.

Function:
Function GetURL(HyperlinkCell As Range)
  Dim arr() As String
  If Not HyperlinkCell.HasFormula Then Exit Function
  arr() = Split(HyperlinkCell.Formula, """")
  GetURL = arr(1)
End Function

Open in new window


How to use the function:
So if your hyperlink formula is in C2, try the following formula in D2 or any other cell as per requirement...

=GetURL(C2)
0
 
frankhelkCommented:
You could use a macro function to extract the hyperlink property:

Public Function HL(c As Range)
    HL = ""
    On Error Resume Next
    HL = c.Hyperlinks(1).Address
End Function

Open in new window


This simple version lacks some smartness, but would handle most cases of cells with hyperlinks. It returns an empty string in case of an error on extracting the hyperlink, i.e. if there's no hyperlink present in the source cell.

You can use it in a cell like this:
=HL(C2)

Open in new window


See attached sample.
ExtractHyperlink.xlsm
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Hi Frank,

As per the formula used by the Asker in the description, I assumed the hyperlinks are inserted through formulas not with inserting hyperlinks through hyperlink wizard.

But both the codes can be combined together to return the hyperlink from a cell irrespective of the method used to insert it. What do you say?

Function GetURL(HyperlinkCell As Range)
   Dim arr() As String
   GetURL = ""
   On Error Resume Next
   arr() = Split(HyperlinkCell.Formula, """")
      If UBound(arr) > 0 Then
         GetURL = arr(1)
      Else
         GetURL = HyperlinkCell.Hyperlinks(1).Address
      End If
End Function

Open in new window

ExtractHyperlink.xlsm
0
 
frankhelkCommented:
Hmmm ... the term "a field of values that are hyperlinked" implies for me i.e. a list of buddies where the names are the cell content and the hyperlink points to the facebook profile ... but anyhow ...

Checking both ways would be better (I've already admitted that my first solution is not as smart as it could get). Small point: Which property to check first depends on what's expected to be more likely ... since a hyperlink property is the more distict way, I'd check that first ... but that's only the icing on top .... ;-)
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Well sequence of checking won't really matter in this case. :)
0
 
Matt PinkstonAuthor Commented:
Tried Solution by SUbodah but all values end up as 0
0
 
Matt PinkstonAuthor Commented:
Sample file attached
USPSSitesx.xlsm
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
No sure what are you trying at your end.
Did you try the solution posted in Post ID: 41727132 and checked the file I uploaded in there?
That file contains both the solutions.
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Since you are not having the hyperlink formulas in the col. C, the solution posted by Frank is enough to extract the addresses in the formula cells.

Refer to the attached.
USPSSitesx.xlsm
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Also if you didn't inserted those hyperlinks through the formulas, why you were using FORMULATEXT function in the formula you posted in post#2?
0
 
Matt PinkstonAuthor Commented:
sorry will not let me open attached file
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
I think that is a temporary bug as I am also having the same issue at my end. I have reported the bug.
Please save the file first and then open it.
0
 
Matt PinkstonAuthor Commented:
nope that does not work either...

is there not just a simple formula or something manual I can do to get the urls into a separate column.  This seems way to complicated.
0
 
frankhelkCommented:
It's quite easy ... just follow the way Subodh pointed out in his first answer (ID: 41726181), but paste the code found in Answer ID: 41727132.

Given a hyperlinked cell in C3, enter in the desired cell (i.e. D3) the formula
=GetURL(C3)

Open in new window


Et voilá ... !

Replicate as desired.
0
 
Matt PinkstonAuthor Commented:
sorry none of the proposed methods worked
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
That's strange.

Did you test the file uploaded in Post ID: 41727611?
In that file I simply copied the code from the Post ID: 41727132 and it worked perfectly when I tested it.

Then what didn't work for you? Will you please elaborate it a bit more?
0
 
frankhelkCommented:
probably you could post an example Excel workbook ?
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
@Frank

He already posted a sample file in the Post ID: 41727604
0
 
frankhelkCommented:
Ooops ... didn't walk back in the thread ... shame on me.

I've had a fresh look at that Excel file ... besides of my Excel nagging about security due to the fact that the file contains data connection, the source fields in column C are exactly what I expected: The content is text, and the cells have a hyperlink attached.

I've just replaced the code in Module1 with the code from post 41727132 and entered the formula
=GetUrl(C2)

Open in new window

into cell X2. Works like a charm.

I've attached that edited sample to this post ... (I know you've already such a sample, but maybe tze asker has more luck with this one)
USPSSitesxExample.xlsm
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
All the needed work has been done by sktneer and frankhelk. The best solution chosen takes care of any type of hyperlink inserted into a cell.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 10
  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now