+ Reply to Thread
Results 1 to 2 of 2

VBA Excel Macro to delete contents in named cell

  1. #1
    reaa
    Guest

    VBA Excel Macro to delete contents in named cell

    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!


  2. #2
    Dave Peterson
    Guest

    Re: VBA Excel Macro to delete contents in named cell

    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.

    reaa wrote:
    >
    > 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!


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1