+ Reply to Thread
Results 1 to 3 of 3

ClearContents method on a passed range

  1. #1
    bryan
    Guest

    ClearContents method on a passed range

    I want to create a range of results in one worksheet based on a range
    of input values in another worksheet in the same workbook. I've
    'named' the input and result ranges in Excel but am unable to clear
    the result range using the following code called from Excel with
    '=Test1(results)' speciified in a cell:

    Public Function Test1(RangeResult As Range)

    RangeResult.ClearContents

    End Function

    The code runs o.k. but the range isn't cleared and zero is returned. I
    thought I was getting the hang of VBA but this has stumped me.

  2. #2
    Harlan Grove
    Guest

    Re: ClearContents method on a passed range

    bryan wrote...
    >I want to create a range of results in one worksheet based on a range
    >of input values in another worksheet in the same workbook. I've
    >'named' the input and result ranges in Excel but am unable to clear
    >the result range using the following code called from Excel with
    >'=Test1(results)' speciified in a cell:
    >
    >Public Function Test1(RangeResult As Range)
    >
    > RangeResult.ClearContents
    >
    >End Function
    >
    >The code runs o.k. but the range isn't cleared and zero is returned. I
    >thought I was getting the hang of VBA but this has stumped me.


    This isn't well documented, but VBA procedures called from worksheet
    formulas can't change anything in the Excel environment.

    When do you want to clear the results range? Why do you need to clear
    the results range rather than write formulas in it which could display
    nothing (so appear cleared) when there's no corresponding inputs?


  3. #3

    Re: ClearContents method on a passed range

    Harlan Grove wrote:
    >
    > This isn't well documented, but VBA procedures called from worksheet
    > formulas can't change anything in the Excel environment.
    >
    > When do you want to clear the results range? Why do you need to clear
    > the results range rather than write formulas in it which could

    display
    > nothing (so appear cleared) when there's no corresponding inputs?


    Thanks for replying.

    The result range is a subset of the input range selected randomly. In
    randomly selecting from the input rage, I wanted to avoid duplicates by
    scanning the entries already selected. To make sure that the result
    range is initially empty, I wanted to clear it.


+ 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