Excel Formula to Extract Hyperlink Addresses From Friendly Names

📅 Oct 02, 2026 📝 Sarah Miller

Managing dynamic data in Excel often becomes frustrating when standard lookup formulas retrieve only the visible "friendly name" of a hyperlink, stripping away the underlying URL. While traditional tools like VLOOKUP or XLOOKUP excel at basic data retrieval, they inherently fail to carry over destination paths.

Implementing a custom extraction method grants you the ability to seamlessly retrieve both display text and active links, preserving vital interactive data. Under the stipulation that native Excel formulas cannot read cell metadata directly without VBA, this approach is essential when auditing supplier registries or client portals.

The following guide details the exact User-Defined Function (UDF) and formula structure required to automate this extraction.

Excel Formula to Extract Hyperlink Addresses From Friendly Names

The Challenge: Why standard Excel Lookups Strip Hyperlinks

Excel formulas like VLOOKUP, XLOOKUP, and INDEX/MATCH are built to do one job: locate and retrieve data values. When you use these formulas to lookup a cell that contains a hyperlink with a custom display name (a "friendly name"), Excel retrieves only the raw string value displayed in the cell. The underlying URL metadata is stripped away, leaving you with static, unclickable text.

This limitation occurs because Excel treats cell values and cell formatting/metadata (such as cell color, fonts, and hyperlinks) as separate layers. Standard lookup functions only access the value layer. To pull both the visible friendly text and the hidden URL destination, you need a method that can read the cell's metadata and reconstruct the clickable link in your target cell.

This comprehensive guide walks you through the best solutions to solve this problem, ranging from a powerful VBA User-Defined Function (UDF) to bulk extraction scripts and modern dynamic formulas.


Method 1: The VBA User-Defined Function (UDF) Solution

The most robust, flexible, and automated way to look up a hyperlink is by creating a custom function in Excel using Visual Basic for Applications (VBA). Once created, this custom function can be used in your worksheet formulas just like any native Excel function.

Step 1: Create the Custom VBA Function

We will write a VBA function called GetURL. This function accepts a cell range as its argument, checks if there is an embedded hyperlink, and returns the URL string. If the hyperlink was created using a formula rather than manual insertion, it will parse that formula to extract the address.

Follow these steps to add the code to your workbook:

  1. Open your Excel workbook.
  2. Press ALT + F11 to open the VBA Editor.
  3. In the menu bar, click Insert > Module.
  4. Copy and paste the following code into the empty module window:
Function GetURL(cell As Range) As String
    Application.Volatile
    On Error Resume Next
    
    ' Check if there is an inserted hyperlink
    If cell.Hyperlinks.Count > 0 Then
        GetURL = cell.Hyperlinks(1).Address
        ' If it is an internal link (anchor sheet link), grab the SubAddress
        If GetURL = "" Then
            GetURL = "#" & cell.Hyperlinks(1).SubAddress
        End If
    ' Check if it is a formula-based HYPERLINK
    ElseIf InStr(1, cell.Formula, "=HYPERLINK(", vbTextCompare) > 0 Then
        Dim formula As String
        Dim startPos As Long, endPos As Long
        formula = cell.Formula
        
        ' Find the start of the first argument
        startPos = InStr(1, formula, "(", vbTextCompare) + 1
        ' Find the separating comma
        endPos = InStr(startPos, formula, ",", vbTextCompare)
        
        If endPos > 0 Then
            Dim urlArg As String
            urlArg = Mid(formula, startPos, endPos - startPos)
            ' Strip out quotation marks
            urlArg = Replace(urlArg, """", "")
            GetURL = Trim(urlArg)
        End If
    Else
        GetURL = ""
    End If
End Function
  • Close the VBA Editor and return to your Excel workbook.
  • Save your file as an Excel Macro-Enabled Workbook (.xlsm) so your custom code is preserved.
  • Step 2: Reconstruct the Clickable Link with INDEX and MATCH

    Now that you have the GetURL function, you can combine it with the native HYPERLINK function to perform a lookup that returns a fully functional, clickable hyperlink with its original friendly name.

    Crucial Technical Note: You must use INDEX/MATCH or XLOOKUP for this trick. Standard VLOOKUP evaluates to a raw text value immediately, meaning you cannot pass its result into our custom GetURL function as a cell reference. INDEX/MATCH, however, returns an actual cell reference, allowing our custom function to inspect the source cell's metadata.

    The Formula Template:

    =HYPERLINK(GetURL(INDEX(LinkColumn, MATCH(LookupValue, KeyColumn, 0))), INDEX(LinkColumn, MATCH(LookupValue, KeyColumn, 0)))

    Step-by-Step Practical Example

    Let's look at a real-world scenario. Suppose you have a Master Sheet containing client websites, and you want to look up those links from a summary worksheet.

    Your Source Data Table (Sheet1):

    Client ID (Column A) Client Portal Link (Column B - Hyperlinks with Friendly Names)
    101 Google Portal
    102 Microsoft Portal
    103 Apple Portal

    On your target worksheet (Sheet2), you have the Client ID in cell A2, and you want to pull the working hyperlink into cell B2.

    The Formula to use in Sheet2, Cell B2:

    =HYPERLINK(GetURL(INDEX(Sheet1!B$2:B$4, MATCH(A2, Sheet1!A$2:A$4, 0))), INDEX(Sheet1!B$2:B$4, MATCH(A2, Sheet1!A$2:A$4, 0)))

    How this formula works:

    • INDEX(Sheet1!B$2:B$4, MATCH(A2, Sheet1!A$2:A$4, 0)) locates the correct cell in the portal column. Because it is nested inside another function, it returns a reference to cell B3 (for ID 102).
    • The first argument of HYPERLINK wraps this reference in our custom GetURL function: GetURL(B3). This successfully extracts the raw URL string ("https://microsoft.com").
    • The second argument of HYPERLINK simply evaluates the INDEX reference as text, pulling the friendly name ("Microsoft Portal").
    • The outer HYPERLINK function puts these two elements together, creating a functional, clickable cell displaying "Microsoft Portal" pointing to "https://microsoft.com".

    Method 2: Bulk Extraction via VBA Macro (No Dynamic Formulas)

    If you prefer not to use complex, nested array formulas or live UDFs that recalculate constantly, you can run a quick one-time macro to extract all hyperlink targets into a clean, adjacent text column. Once the URLs are written out as plain text, you can use regular VLOOKUP or XLOOKUP without any workarounds.

    VBA Code to Extract All Links in a Selected Column:

    Add this macro to your VBA module, select the cells containing your hyperlinks, and run the macro:

    Sub ExtractSelectedHyperlinks()
        Dim cell As Range
        Dim targetCell As Range
        
        ' Loop through each cell in the user's current selection
        For Each cell In Selection
            ' Make sure the cell contains at least one hyperlink
            If cell.Hyperlinks.Count > 0 Then
                ' Write the URL to the column immediately to the right
                cell.Offset(0, 1).Value = cell.Hyperlinks(1).Address
            End If
        Next cell
        MsgBox "Hyperlinks extracted successfully!", vbInformation
    End Sub
    

    With the URLs extracted into a dedicated column next to your display names, a simple lookup formula can easily fetch either the name or the URL whenever needed.


    Troubleshooting Common Errors

    When working with customized functions and cell metadata, you may encounter a few common errors. Use this quick reference guide to resolve them:

    Error Observed Underlying Cause Actionable Solution
    #NAME? Excel doesn't recognize the GetURL function. Verify that you pasted the VBA code into a standard "Module" and not inside a Sheet object or "ThisWorkbook". Ensure the file is saved as .xlsm.
    #VALUE! A lookup function (like VLOOKUP) is returning raw data instead of a cell reference. Swap your formula to use INDEX/MATCH or XLOOKUP as shown in the template to feed a proper cell reference into GetURL.
    Blank URL Output The link targets an internal sheet/bookmark rather than an external website. Ensure your GetURL code handles the SubAddress property (our provided script is already configured to do this by appending a "#").

    Best Practices When Managing Excel Hyperlinks

    • Keep Formulas Consistent: Avoid mixing manually inserted hyperlinks (using the right-click menu or Ctrl+K) and formula-driven hyperlinks (using the =HYPERLINK() function) in the same column, as they are stored differently in Excel's file structure.
    • Perform Cleanups regularly: Broken URLs and ghost links can slow down your macro performance. Use Excel's "Find and Replace" or clear formatting tools to keep your database clean.
    • Mind Your File Security: Since UDFs require Macro-Enabled Workbooks (.xlsm), ensure your organization allows macros or add your file's folder to the "Trusted Locations" in Excel's Trust Center to prevent security warnings on startup.

    Disclaimer:
    The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.