Public Sub Check_Hyperlink_FormulasX()
Dim hyperlinkCells As Range, hyperlinkCell As Range
Dim linkLocation As String
With ActiveSheet
Set hyperlinkCells = .Range("K4", .Cells(Rows.Count, "K").End(xlUp))
End With
For Each hyperlinkCell In hyperlinkCells
linkLocation = EvaluateHyperlinkLocation(hyperlinkCell)
If linkLocation <> "" Then
If Dir(linkLocation) <> "" Then
hyperlinkCell.Offset(0, 1).Value = "Valid"
Else
hyperlinkCell.Offset(0, 1).Value = "Invalid"
End If
End If
Next
End Sub
Private Function EvaluateHyperlinkLocation(HyperlinkFunctionCell As Range) As String
'Given a cell containing a HYPERLINK function, returns what the link_location parameter evaluates to
Dim p1 As Long, p2 As Long
EvaluateHyperlinkLocation = ""
p1 = InStr(1, HyperlinkFunctionCell.Formula, "HYPERLINK(", vbTextCompare)
If p1 > 0 Then
p1 = p1 + Len("HYPERLINK(")
p2 = InStr(p1, HyperlinkFunctionCell.Formula, ",")
If p2 = 0 Then p2 = InStr(p1, HyperlinkFunctionCell.Formula, ")") 'optional friendly_name parameter not present
EvaluateHyperlinkLocation = Evaluate(Mid(HyperlinkFunctionCell.Formula, p1, p2 - p1))
End If
End Function