+ Reply to Thread
Results 1 to 5 of 5

Create custom function which contains other functions

  1. #1
    Registered User
    Join Date
    11-18-2019
    Location
    Paris
    MS-Off Ver
    Office 2016
    Posts
    80

    Create custom function which contains other functions

    Hi there,

    I'm looking for something really peculiar. This is my first time creating a function and I'm having trouble building it.
    To give a bit of context, I'm creating an Excel spreadsheet with macros in it. I put a password to access the macro because there are hidden sheets. But it already happened to me that one of my students opened the Excel File in Google Sheets to see the hidden sheets...

    In order to prevent a case like that from happening, I'm looking at creating a function that would contain all other functions in my Workbook. I started with

    Please Login or Register  to view this content.
    The idea of creating my custom function is that it cannot be read by Google Sheets.

    But I cannot manage to build it. In my case, the final result would be:
    =TestFormula(SUM(A1:A4)) or
    =TestFormula(TEXT(A1,"hh:mm"))

    I want it to work both with text and numbers. My guess was to go with both N() and T() functions.

    Could you please help with this one?

    Thanks!

    Okela
    Attached Files Attached Files
    Last edited by okela; 09-14-2020 at 11:21 AM.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Create custom function which contains other functions

    You can't use worksheet functions directly in VBA.

    You'll need to use WorksheetFunction.FunctionName or Application.FunctionName.

    However, N() and T() can't be used in this manner. For list of functions, type WorksheetFunction. in VBE and check options available.

    If I guessed correctly, you'd want to convert both numeric value and text value to numeric?

    If that's the case... try using CDbl().
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    11-18-2019
    Location
    Paris
    MS-Off Ver
    Office 2016
    Posts
    80

    Re: Create custom function which contains other functions

    Hi CK76,

    Many thanks for your answer. I've understood your point.
    We're almost there.

    With the function you gave me, it works with numeric results but I also need it to work with text results. Could you please help me?

    Thanks!

    Okela

  4. #4
    Registered User
    Join Date
    11-18-2019
    Location
    Paris
    MS-Off Ver
    Office 2016
    Posts
    80

    Re: Create custom function which contains other functions

    Ok I managed to do it with the following code:

    Please Login or Register  to view this content.
    Many thanks for your guidance CK76!

    Okela

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Create custom function which contains other functions

    You are welcome

    If your issue is resolved. Please mark the thread as solved using thread tools found at top of your initial post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Usage of standard functions into custom function (or user defined function)
    By tusharb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2016, 12:43 AM
  2. Create custom function to exceed 7 nested If functions in Excel 2003/XP/2000/97
    By seanyeap in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2008, 08:54 AM
  3. [SOLVED] Need to reference existing functions in a custom function: possibl
    By dofnup in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 PM
  4. Need to reference existing functions in a custom function: possibl
    By Max in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-06-2005, 02:05 PM
  5. [SOLVED] Need to reference existing functions in a custom function: possibl
    By Max in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-06-2005, 07:05 AM
  6. Need to reference existing functions in a custom function: possibl
    By Max in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-06-2005, 04:05 AM
  7. [SOLVED] Need to reference existing functions in a custom function: possibl
    By dofnup in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM

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