Created
June 1, 2020 03:31
-
-
Save natl/2bac21e4ed540a574d2dca61217472f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sub ExtractHL() | |
| ' | |
| ' Macro1 Macro | |
| ' Extract hyperlink from cell in first column in Excel | |
| ' | |
| Dim HL As Hyperlink | |
| Dim xCell As Range | |
| Dim char As Integer | |
| Columns("B:C").Select | |
| Selection.Insert Shift:=xlToRight | |
| Range("B1").Value = "Link Text" | |
| Range("C1").Value = "Link URL" | |
| For Each xCell In Range("A2:A" & Rows.Count) | |
| If InStr(1, xCell.Formula, "=HYPERLINK") = 1 Then | |
| char = InStr(13, xCell.Formula, """") | |
| ' Set Bx to link text | |
| xCell.Offset(0, 1).Value = Mid(xCell.Formula, char + 4, InStr(char + 4, xCell.Formula, """") - char - 4) | |
| ' Set Cx to link URL | |
| xCell.Offset(0, 2).Value = Mid(xCell.Formula, 13, char - 13) | |
| Else | |
| For Each HL In xCell.Hyperlinks | |
| ' Set Bx to link text | |
| xCell.Offset(0, 1).Value = HL.TextToDisplay | |
| ' Set Cx to link URL | |
| xCell.Offset(0, 2).Value = HL.Address | |
| Next | |
| End If | |
| Next | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment