+ Reply to Thread
Results 1 to 5 of 5

Convert Array Formula into VBA User Defined Function

Hybrid View

hhhhwong Convert Array Formula into... 03-25-2013, 03:14 AM
JosephP Re: Convert Array Formula... 03-25-2013, 03:40 AM
hhhhwong Re: Convert Array Formula... 04-03-2013, 03:08 AM
JosephP Re: Convert Array Formula... 04-03-2013, 08:25 AM
hhhhwong Re: Convert Array Formula... 04-05-2013, 12:38 AM
  1. #1
    Registered User
    Join Date
    03-25-2013
    Location
    China
    MS-Off Ver
    Excel 2003
    Posts
    3

    Question Convert Array Formula into VBA User Defined Function

    I want to convert the below count & if function into a user defined function. However, its outcome is false. What's wrong with it? Can someone helps?? Thanks in advance!

    Public Function TestFunction()
    
    Result = Selection.FormulaArray = _
            "=COUNT(IF(Data!R2C3:R9999C3>R1C,IF(IF(Data!R2C1:R9999C1>R[-1]C1,Data!R2C1:R9999C1)<=RC1,Data!R2C3:R9999C3)))"
    
    TestFunction = Result
    
    End Function

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Convert Array Formula into VBA User Defined Function

    that function only tests if the current selection contains the formula specified in the code. you need to use evaluate if you want to actually calculate that formula but I am not sure what the benefit of the udf is-the formula in the cell would be more efficient
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    03-25-2013
    Location
    China
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Convert Array Formula into VBA User Defined Function

    Thanks Joseph! The reason is I want to hide my calculation. I have to let the user to know the raw data but cannot let them know to calculate it!

    I have changed my code but the outcome is still "FALSE". Are there any problems?

    Public Function TimeGroup()
    
    TimeGroup = Evaluate(ActiveCell.FormulaArray = _
            "=COUNT(IF(Data!R4C3:R9999C3>R5C,IF(IF(Data!R4C1:R9999C1>R[-1]C2,Data!R4C1:R9999C1)<=RC2,Data!R4C3:R9999C3)))")
    
    End Function

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Convert Array Formula into VBA User Defined Function

    yes-the code is wrong and the formula makes no sense. what is the formula supposed to do?

  5. #5
    Registered User
    Join Date
    03-25-2013
    Location
    China
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Convert Array Formula into VBA User Defined Function

    The code is obtained from Macro recording but it doesn't work in module.

    I want to use a User defined function to replace the formula in the spreadsheet "Master Table" of the attached file.
    Attached Files Attached Files

+ 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