Removing Names

Giordano Bruno

Well-known Member
Joined
Jan 7, 2007
Messages
1,231
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?
 

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Macropod

Retired Moderator
Joined
Aug 27, 2007
Messages
3,511
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,231
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,193
Messages
5,594,774
Members
413,934
Latest member
austinb

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