VBA Excel Macro to delete contents in named cell

  • Thread starter Thread starter reaa
  • Start date Start date
R

reaa

I have several named cells in an MS excel workbook, starting with the
word "clr_". I'm looking for a looping statement that would look for
how many names there are in the workbook beginning with "clr_" and then
go through a loooping statement to delete the contents in that named
cell. For example, clr_projectname might have the words "My Project"
and i want the words "my project" to be deleted from the cell. I have
about 30 variables to be deleted. Anyone's help would be appreciated!
 
Maybe something like:

Option Explicit
Sub testme()

Dim myName As Name

For Each myName In ActiveWorkbook.Names
If LCase(myName.Name) Like "clr_*" _
Or LCase(myName.Name) Like "*!clr_*" Then
On Error Resume Next
myName.RefersToRange.ClearContents
On Error GoTo 0
End If
Next myName

End Sub


clr_* will catch the workbook level names
*!clr_* will catch the worksheet level names

The on error stuff is there just in case that name doesn't refer to a range.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top