Hyperlink with an Excel Formula
Excel article and video for CPAs
Let’s say you have a hyperlink in a cell in Excel. The hyperlink may have friendly text, such as Click Here, but when you click the link it takes you to a URL such as https://www.excel-university.com. Now, let’s say you want to extract that URL from the hyperlink using an Excel formula.
Well … to my knowledge, there isn’t a built-in function to accomplish that. But, we can actually create our own custom function, and even name it URL if we’d like, using a few lines of code. I’ll walk you through each step so it will be easy to implement. And thanks to my friend Cary who asked how to extract a url from a hyperlink which led to this post!
Overview
Before we get too far, let’s confirm what we are trying to accomplish. We have a hyperlink, or maybe several hyperlinks, in some Excel cells. Like this:

We would like to be able to write some type of formula like =URL(B7) to extract the underlying URL from the links, like this:
Although (at the time of this writing) Excel doesn’t have a built-in URL function, we can create our own custom URL function using a few lines of code.
I’ll break the entire process down into bite-sized steps. Ready? Let’s do this.
Steps to extract a URL from a hyperlink
We’ll accomplish our objective with the following steps:
- Create the URL function
- Use the function to extract the URL
- Save workbook as XLSM
Let’s start with creating the custom URL function.
Create the URL function
We’ll need to add our custom URL function to the workbook.
Note: if you want to skip this step, I already created the URL function in the Sample File below. So, rather than creating it yourself, you can certainly just download the workbook and get on with it. But, if you are curious about how it works, keep reading and I’ll explain the details.
The first thing we need to do is open the Visual Basic Editor. This can be accomplish by using the Alt+F11 keyboard shortcut in Excel for Windows, and I believe Opt+F11 (or Fn+Opt+F11) in Excel for Mac.
Next, we need to insert a new Module into the workbook. To do so, locate the workbook in the Project Explorer panel … it should say something like VBAProject (Workbookname) like this:
Note: if you don’t see the Project Explorer panel, use the Ctrl+R keyboard shortcut to toggle it on.
Then, right-click the workbook name and select Insert > Module. You’ll see a new Module1 appear in a new folder called Modules, like this:
Next, double-click Module1 so it opens. You’ll see a blank window that feels a little bit like a word-processor because you can type stuff there. You could type the custom function code, but it will be faster to copy/paste. So, copy this VBA code:
__
Function URL(Hyperlink As Range)
URL = Hyperlink.Hyperlinks(1).Address
End Function
__
And then paste it into Module1. It should look like this:
Believe it or not … the hard part is done!!!!!!!!!!!!!!!!
You can now toggle back to your Excel screen or close the Visual Basic Editor.
With the custom function complete, it is time to use it to extract the URLs from our hyperlinks.
Note: custom functions are stored inside workbooks rather than inside of the Excel application. This is good because other people that open the workbook can use the custom function. But, it also means you’ll either need to use this workbook for other URL extraction projects or create the custom function in other workbooks as needed.
Conclusion
Well, that is one way to extract a URL from a hyperlink using an Excel formula. If you have any other preferred methods or improvements to this one, please share by posting a comment below … thanks!
Sample file
Learn MoreShare This Article
What's Trending?
Trending topics & tools for the CPA community
How Firms are Rethinking Reasonable Comp (Quick Video)
It’s a short video and makes the value of repeatable, data-backed approach clear (especially compared to spreadsheets, gut checks and one-off calculations).
Learn how 8am CPACharge delivers clarity and confidence for accounting firms.
8am™ CPACharge brings invoices, payments, and reconciliation together in a solution designed to make your day easier from start to finish.
Seniors on Social Security Could Face $460 Monthly Cut to Benefits
Jim Komoroski, RSSA®, is quoted in Newsweek, offering expert insight into the projected monthly cuts to Social Security benefits should Congress fail to act.
Resources
Valuable information provided by our sponsors.
Specialize in Social Security
Looking to enhance your retirement planning expertise? Your solution: pursue the Registered Social Security Analyst®...
CPAdirectory members have access to discounted auto and home insurance
At CPAdirectory, we think it's a good thing to provide our members with access to...
Free CPE Course: ChatGPT for Tax Pros — Limited Offer
CPAdirectory and CCH CPELink are giving you free access to the on-demand course: ChatGPT for...
PE Deals In Accounting: Valuations, Structure, Tradeoffs
In this webinar, you’ll hear from firm leaders and industry experts who will share real-world...
Stand Out as a Trusted Social Security Expert with the RSSA® Designation
Designed for CPAs, the Registered Social Security Analyst® (RSSA®) designation provides advanced training to help...
How Firms are Rethinking Reasonable Comp (Quick Video)
It’s a short video and makes the value of repeatable, data-backed approach clear (especially compared...