This will start in C8 and A1 and process until it encounters an empty cell
Sub Diver()
Dim s1 As Worksheet, s2 As Worksheet
Dim inputCell As Range
Dim outputCell As Range
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
Set inputCell = s2.Range("C8")
Set outputCell = s1.Range("A1")
Do While Len(inputCell.Value) > 0
outputCell.Value = inputCell.Value
m_ConvertFormulaToHyperlink inputCell, outputCell
Set inputCell = inputCell.Offset(1, 0)
Set outputCell = outputCell.Offset(1, 0)
Loop
End Sub
Private Sub m_ConvertFormulaToHyperlink(InCell As Range, OutCell As Range)
Dim linkAddress As String
Dim linkText As String
Dim pos As Long
Dim formulaText As String
Dim linkRange As Range
formulaText = InCell.Formula
pos = InStr(1, formulaText, "HYPERLINK(", vbTextCompare)
If pos > 0 Then
' formula contains HYPERLINK function so extract the two arguments
linkAddress = Split(Mid(formulaText, pos + 10), ",")(0)
' check is the argument is a range reference
On Error Resume Next
Set linkRange = Range(linkAddress)
On Error GoTo 0
If Not linkRange Is Nothing Then
linkAddress = linkRange.Value
End If
linkText = Split(Split(Mid(formulaText, pos + 10), ",")(1), ")")(0)
' check is the argument is a range reference
On Error Resume Next
Set linkRange = Range(linkText)
On Error GoTo 0
If Not linkRange Is Nothing Then
linkText = linkRange.Value
End If
' add hyperlink to A1
OutCell.Hyperlinks.Add OutCell, linkAddress, "", linkText, linkText
End If
End Sub
Bookmarks