Skip to content

Instantly share code, notes, and snippets.

@johnBrooksHoffman
Created November 4, 2014 06:39
Show Gist options
  • Save johnBrooksHoffman/3c4ccb86e5de3c349e30 to your computer and use it in GitHub Desktop.
Save johnBrooksHoffman/3c4ccb86e5de3c349e30 to your computer and use it in GitHub Desktop.
This is a simple Excel macro that converts a selection of cells into hyperlinks. It's intended for use on large blocks of URLs stored as plain text.
Sub Hyperlinker()
Dim rng As Range, workingRng As Range
Set workingRng = Application.Selection
'Code to set boundaries for workingRng, in case user selects entire row, column, or sheet
Set workingRng = Range(Cells(workingRng.Row, workingRng.Column), Cells(lastRowInColumn(workingRng.Column), lastColumnInRow(workingRng.Row)))
For Each rng In workingRng
Application.ActiveSheet.Hyperlinks.Add rng, rng.Value
Next rng
End Sub
Private Function lastRowInColumn(columnRef As Long) As Long
lastRowInColumn = Cells(65536, columnRef).End(xlUp).Row
End Function
Private Function lastColumnInRow(rowRef As Long) As Long
lastColumnInRow = Cells(rowRef, Columns.Count).End(xlToLeft).Column
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment