Remove links to other documents, but text/number to remain

Goddess

Board Regular
Joined
Dec 3, 2015
Messages
94
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I have a spreadsheet with

1) links to other tabs - example: ='General Info'!$E$9
2) links to external documents - example: ='Sign in to your Microsoft account

Is there a way to remove the external links (item 2) while retaining the text or number? I tried to copy and paste number only; it worked if I manage to identify where the external links are located. If I copy and paste all, the links to the other tabs (item 1) will go missing too.

Thanks!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
adjust as you need since this scans column A.

Code:
Sub RemoveSomeLinks()
Dim vLnk
Dim iCt As Integer

On Error GoTo errScan

 'scan col. A only.
Range("A1").Select

While ActiveCell.Value <> ""
    iCt = Selection.Hyperlinks.Count
    If iCt = 0 Then
        vLnk = ""
    Else
        vLnk = Selection.Hyperlinks(1).SubAddress
    End If
    
    
    Select Case True
        Case iCt = 0
            'no link
           Debug.Print ActiveCell.Address, "no link"
        Case InStr(vLnk, "!") > 0
             'keep cell link
           Debug.Print ActiveCell.Address, vLnk
        Case Else
             'delete external link
           Selection.Hyperlinks.Delete
    End Select

    ActiveCell.Offset(1, 0).Select 'next row
Wend
Exit Sub
errScan:
If Err = 450 Then
    vLnk = ""
    Resume Next
Else
MsgBox Err.Description, , Err
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,197
Messages
6,123,581
Members
449,108
Latest member
rache47

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