Delete external named range

theta

Well-known Member
Joined
Jun 9, 2009
Messages
960
Hi

I have a workbook that contains named ranges linked to another sheet

I need a macro to delete all external named ranges

I copy a sheet ("Client data") that contains vlookups etc that contain named table ranges

A macro then pastes these external formulas as values

So now need to delete named ranges

My ***IDEAL*** solution would be to modify the below code so that if a cell contains an external ref (currently does this) or has a named range that has an external ref (would like it to do this) then it will paste as values

Maybe then call another function to delete all external ref named ranges? (keep the functions seperate so I can use one and not the other when the choice suits)

Code:
Function DeleteLinks(ws As Worksheet)
'Convert external formula links to values
Dim r As Range, sFormula As String, i As Integer
    If ws Is Nothing Then Exit Function
    ws.Activate
    For Each r In ws.UsedRange
'        If Len(sFormula) > 0 Then
        If r.HasFormula = True Then
            sFormula = r.Formula
            If Left$(sFormula, 1) = "=" Then
                If InStr(sFormula, "[") > 1 Then
                            On Error Resume Next
                            ' in case the worksheet is protected
                            r.Formula = r.Value
                            On Error GoTo 0
                End If
            End If
        End If
    Next r
    Set r = Nothing
    End If
End Function
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Won't simply breaking the links do everything you need?
 
Upvote 0
What would be the best way to do this using VBA?

Maybe as a function so that I may call it several times...
 
Upvote 0
Edit the links, and break links while using the macro recorder. Is the code generated any use? This would be a subroutine or macro, and not a "Function".
 
Upvote 0
Hi Glenn

Break links works fine...but external named ranges just become #REF

Is there any VBA to delete external named ranges?

(or named ranges that are #REF, although I think both instances are different in principle)
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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