VBA & Macro Problems

Automatically Extract Hyperlink URLs from Excel Column A with VBA

Olivia MillerOlivia Miller Nov 12, 2026 869 views

Question details

Automatically copy the URL behind hyperlinks in Excel column A to the adjacent column whenever the source cells are changed.

Automatically Extract Hyperlink URLs from Excel Column A with VBA
Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
The user wants a worksheet-level automation that extracts hyperlink addresses from column A into column B for existing and newly edited cells.
Observed behavior
A regular worksheet formula does not automatically populate URL values for hyperlinks added to new rows later.
Before you start

Save the workbook as an Excel Macro-Enabled Workbook (*.xlsm) before adding VBA code. Open the Visual Basic Editor with Alt+F11 and make sure you add the event procedure to the specific worksheet module, not to a standard module.

Solution 1Recommended

Use a Worksheet_Change macro to copy hyperlink URLs to column B

Use this option when URLs should be extracted automatically after cells in column A are edited or pasted.

This worksheet event checks changed cells in column A. If a cell has a hyperlink, its first hyperlink address is written to the corresponding cell in column B; otherwise, the cell in column B is cleared.

1
Open the target worksheet module

In Excel, press Alt+F11 to open the Visual Basic Editor. In the Project Explorer, expand your workbook, expand Microsoft Excel Objects, and double-click the worksheet that contains the hyperlinks.

2
Paste the worksheet event code

Paste the following code into that worksheet code window: Private Sub Worksheet_Change(ByVal Target As Range) Dim cell As Range If Intersect(Target, Me.Columns("A")) Is Nothing Then Exit Sub For Each cell In Intersect(Target, Me.Columns("A")) If cell.Hyperlinks.Count > 0 Then cell.Offset(0, 1).Value = cell.Hyperlinks(1).Address Else cell.Offset(0, 1).ClearContents End If Next cell End Sub

3
Save and enable the macro

Choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm). When reopening the file, select Enable Content in Excel's security warning.

4
Test a hyperlink cell

Add, paste, or edit a hyperlink in column A, then check the matching row in column B. The macro writes the hyperlink URL to column B when the worksheet change event runs.

Use a Worksheet_Change macro to copy hyperlink URLs to column B
Some hyperlink insert actions may not trigger the event: Adding a hyperlink through certain Excel dialog actions may not trigger Worksheet_Change. If that happens, use a separate scan macro or create links with the HYPERLINK function.
WPS Spreadsheet automation

Extract Hyperlink URLs with WPS Spreadsheet Macros

WPS Spreadsheet provides a familiar worksheet environment for organizing hyperlink lists and automating repetitive URL extraction. Open a macro-enabled workbook, use the macro editor to add compatible automation code, and keep the hyperlink address results in an adjacent column.

  1. 1. Open the workbook in WPS Spreadsheet: Launch WPS Office and open the Excel workbook containing hyperlinks in column A.
  2. 2. Access macro tools: Use the Developer or Macro tools in WPS Spreadsheet to open the macro editor for the workbook.
  3. 3. Add the hyperlink extraction routine: Insert the worksheet event code or a scan macro, then set column B as the output column for extracted addresses.
  4. 4. Save as a macro-enabled workbook: Use File > Save As and choose a macro-enabled workbook format when available so the automation remains with the file.
Automate hyperlink URL extraction from a worksheet column.Use a familiar spreadsheet interface for macro-enabled workbooks.Open and save Microsoft Excel .xlsx and macro-enabled .xlsm workbook formats.Maintain adjacent URL columns for sorting, filtering, and review.
microsoft office alternative - wps office

Frequently Asked Questions

Where should I paste the Worksheet_Change code in Excel?

Paste it into the code module for the specific worksheet that contains the hyperlinks. In the Visual Basic Editor, under Microsoft Excel Objects, double-click that worksheet and paste the procedure there.

Why does the hyperlink URL not appear in column B after I insert a link?

Some links added through Excel's Insert Hyperlink dialog do not trigger Worksheet_Change. Run a separate scan macro for column A, or use the HYPERLINK function when creating the link.

Can the macro extract URLs from multiple changed cells at once?

Yes. The For Each cell loop processes every changed cell within column A, including a range of cells pasted into the column.

Does this macro work with display text that is different from the URL?

Yes. The code reads cell.Hyperlinks(1).Address, which is the hyperlink destination rather than the visible display text.

Why must the workbook be saved as an XLSM file?

The .xlsx format cannot retain VBA code. Save the workbook as Excel Macro-Enabled Workbook (*.xlsm) and enable macros when opening it.