I’ve often found myself facing a lengthy column of hyperlinks in an Excel spreadsheet, needing to extract the embedded URLs for a dataset or some data analysis. It can be quite tedious to manually click on each cell, edit the hyperlink, and then copy and paste the URL elsewhere. Thankfully, with a bit of VBA—a programming language used within Microsoft Excel—we can simplify the process significantly by creating a User Defined Function, or UDF. This little bit of code automates extracting URLs from hyperlinks, saving a heap of time and effort.
In the spreadsheet world, mastering such techniques not only enhances productivity but also opens up a world of possibilities for managing and analyzing data. Whether you’re dealing with a small dataset or a mammoth spreadsheet, this tool can be a real game-changer. The ability to swiftly pull out URLs from hyperlinks with the help of a VBA UDF has become one of my favorite Excel tricks to share with colleagues, empowering them to streamline their workflow when handling similar tasks.
VBA code to Extract Hyperlink URLs
Function GiveMeURL(rng As Range) As String
GiveMeURL = rng.Hyperlinks(1).Address
End Function
- Add this VBA macro to a module in Excel to extract URLs from hyperlinks.
- Access the Visual Basic Editor via the Developer tab.
- Create a user-defined function called
GiveMeURL
. - Utilize by calling
=GiveMeURL(A1)
replacingA1
with your desired cell reference.
How to use this Code
Here’s how I easily automate the extraction of URLs from hyperlinks in Excel:
- I hit ALT + F11 to bring up the Visual Basic Editor.
- Then, I insert a new module and drop in the code.
- After closing the editor, back in my sheet, I type
=GiveMeURL(A1)
and press Enter. - Voilà! The URL appears like magic.
Don’t forget to grab the necessary file before you start: Download here.
Note: This manual process sidesteps any context menu fuss!