dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] Why does this simple UDF fail?

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,148

    Resolved [RESOLVED] Why does this simple UDF fail?

    I have a column with a few random values in it including two instances of "aa" and the following formula returns 2 as it should.
    Code:
    =COUNTIF(A1:A10,"aa")
    Why does this UDF fail with a #VALUE! error when I enter =CountValues(A1:A10,"aa") in the formula bar?

    Code:
    Function CountValues(r As Range) As Integer 
        
    CountValues = Application.WorksheetFunction.CountIf(Range(r.Address), "aa")
    
    End Function

  2. #2
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Why does this simple UDF fail?

    Quote Originally Posted by MartinLiss View Post
    ...Why does this UDF fail with a #VALUE! error when I enter =CountValues(A1:A10,"aa") in the formula bar?

    Code:
    Function CountValues(r As Range) As Integer 
        
    CountValues = Application.WorksheetFunction.CountIf(Range(r.Address), "aa")
    
    End Function
    Because CountValues takes only a Range argument.

  3. #3

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width