Removing Names

Giordano Bruno

Well-known Member
Joined
Jan 7, 2007
Messages
1,255
I use a program called @RISK and it has the unfortunate habit of adding thirty names to any spreadsheet that is loaded while it is running.

All of the names commence with the word "risk", e.g. RiskRunAfterRecalcMacro.

I need some code that will look a the collection Names in active workbook and delete all names which start with "risk".

Any ideas?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Macropod

Retired Moderator
Joined
Aug 27, 2007
Messages
3,613
Hi Giordano,

Try:
Option Explicit

Code:
Sub KillRiskNames()
Dim oName As Name
For Each oName In ActiveWorkbook.Names
    If Left(oName.Name, 4) = "Risk" Then oName.Delete
Next
End Sub

Cheers
 

ravishankar

Well-known Member
Joined
Feb 23, 2006
Messages
3,566
HI

Assuming the names are in col A, try these codes

Code:
Sub remove()
x = Cells(Rows.Count, 1).End(xlUp).Row
For a = 1 To x
If Left(Cells(a, 1), 4) = "risk" Then
Cells(a, 1).ClearContents
End If
Next a
End Sub
run the macro. it will clear the cell if it contains risk at the beginning of the string.
ravi
 

Giordano Bruno

Well-known Member
Joined
Jan 7, 2007
Messages
1,255
ravishankar,

I'm sorry that my post was unclear. The names are added as named ranges, not text on a worksheet, but thanks for your interest.

Macropod,

Thanks for the code. Works perfectly. It will be very useful in the future also as this is a persistant problem.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,157
Messages
5,835,715
Members
430,382
Latest member
legolas97

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
Top