create hyperlink automatically

srikanthg2310

New Member
Joined
Nov 9, 2015
Messages
17
I am looking for a vba code which will do the following:
1. Check if each cell is referencing any other cell in the workbook
2. If true, then automatically create a hyperlink to the referenced cell.
3. The code should loop through every cell in the workbook which is not vacant.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Assumption: when you said "referencing", I assume that it means referencing without the referenced cell used in a function. Basically, the following code will work for the formulas like this: =Sheet2!A1, not for the formulas like this: =ABS(Sheet2!A1) or =Sheet2!A1 + 1.
Is this second version possible? I am not a fan of using dependents/precendents in VBA since they are the most unreliable objects in VBA (my opinion) but it should be possible. In that case, someone good at it might help. Until then, please try the following code.

Activate the worksheet and run the code. Make sure to work on a backup. copy of your workbook.

VBA Code:
Sub createHyperlinks()
Dim rng As Range
Dim cll As Range
Dim trg As Range
    Set rng = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas)
    For Each cll In rng.Cells
        On Error Resume Next
        Set trg = Range(Right(cll.Formula, Len(cll.Formula) - 1))
        If Err.Number = 0 Then
            With cll.Hyperlinks
                .Delete
                .Add cll, "", cll.Formula
            End With
        End If
    Next cll
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,360
Messages
6,124,493
Members
449,166
Latest member
hokjock

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top