Solved

Excel Field with URL

Posted on 2016-07-23
21
50 Views
1 Endorsement
Last Modified: 2016-08-22
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
Comment
Question by:Matt Pinkston
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 6
  • 5
21 Comments
 

Author Comment

by:Matt Pinkston
ID: 41726092
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
 
LVL 30

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41726181
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
 
LVL 14

Assisted Solution

by:frankhelk
frankhelk earned 250 total points (awarded by participants)
ID: 41727111
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 250 total points (awarded by participants)
ID: 41727132
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
 
LVL 14

Expert Comment

by:frankhelk
ID: 41727149
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
 
LVL 30

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41727154
Well sequence of checking won't really matter in this case. :)
0
 

Author Comment

by:Matt Pinkston
ID: 41727597
Tried Solution by SUbodah but all values end up as 0
0
 

Author Comment

by:Matt Pinkston
ID: 41727604
Sample file attached
USPSSitesx.xlsm
0
 
LVL 30

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41727608
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
 
LVL 30

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41727611
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
 
LVL 30

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41727615
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
 

Author Comment

by:Matt Pinkston
ID: 41727652
sorry will not let me open attached file
0
 
LVL 30

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41727695
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
 

Author Comment

by:Matt Pinkston
ID: 41727766
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
 
LVL 14

Expert Comment

by:frankhelk
ID: 41727859
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
 

Author Comment

by:Matt Pinkston
ID: 41731031
sorry none of the proposed methods worked
0
 
LVL 30

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41731035
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
 
LVL 14

Expert Comment

by:frankhelk
ID: 41731047
probably you could post an example Excel workbook ?
0
 
LVL 30

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41731054
@Frank

He already posted a sample file in the Post ID: 41727604
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 41732540
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
 
LVL 30

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41757587
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question