+ Reply to Thread
Results 1 to 3 of 3

For Loops and Named ranges

  1. #1
    Ronnie
    Guest

    For Loops and Named ranges

    I have ranges named in my worksheet (ques1, ques2, etc) and I would like to
    use a loop to clear the contents of these ranges.

    Something like:
    For i = 1 To 60
    Range("ques i ").Select
    Selection.ClearContents
    Next i
    End Sub

    Any suggestions on how to make this work?

  2. #2
    Jim Thomlinson
    Guest

    RE: For Loops and Named ranges

    Give this a whirl...

    For i = 1 To 60
    Range("ques " & i).ClearContents
    Next i
    End Sub

    --
    HTH...

    Jim Thomlinson


    "Ronnie" wrote:

    > I have ranges named in my worksheet (ques1, ques2, etc) and I would like to
    > use a loop to clear the contents of these ranges.
    >
    > Something like:
    > For i = 1 To 60
    > Range("ques i ").Select
    > Selection.ClearContents
    > Next i
    > End Sub
    >
    > Any suggestions on how to make this work?


  3. #3
    Gary Keramidas
    Guest

    Re: For Loops and Named ranges

    if you want to clear all of the ranges

    Option Explicit
    Dim nm As Name

    Sub Clear_rnge()
    For Each nm In ThisWorkbook.Names
    Range(nm).ClearContents
    Next
    End Sub

    --


    Gary


    "Ronnie" <[email protected]> wrote in message
    news:[email protected]...
    >I have ranges named in my worksheet (ques1, ques2, etc) and I would like to
    > use a loop to clear the contents of these ranges.
    >
    > Something like:
    > For i = 1 To 60
    > Range("ques i ").Select
    > Selection.ClearContents
    > Next i
    > End Sub
    >
    > Any suggestions on how to make this work?




+ 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