+ Reply to Thread
Results 1 to 8 of 8

Macro to write custom function into cells

  1. #1
    Registered User
    Join Date
    12-20-2006
    Posts
    11

    Macro to write custom function into cells

    Hi

    I've created a custom function call 'hours' that I've put into every cell in a large table. It uses two variables 'project' and 'plan_date'. See first part of this below:

    Please Login or Register  to view this content.
    My problem is that I don't want this to automatically recalculate, as it slows everything down, but I don't want to switch the whole workbook to manual calculation as others have to use it.

    I thought I'd write a separate macro to enter the formula into the cells then paste special to just store the values in the table. The idea being that I'd call this macro every time I wanted to update the table.

    Below is the code I tried just in one cell

    Please Login or Register  to view this content.
    When I run this, I get runtime error '13' type mismatch. The debugger takes me to the line in the function where Gate_A2 is defined. This is the first time that 'project' is referenced so I'm guessing that there's some issue with the order that excel is doing things and it isn't picking up that 'project' is defined by the function.

    The formula works fine if I type it in manually.

    Hope this makes sense, any ideas how I can get rid of the runtime error?

    Thanks,

    Rob

  2. #2
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Macro to write custom function into cells

    Dim scheme_data as Range, not Variant
    Gate_A2, B and C are being declared as variants. Each need their own separate 'As Date'. Only ACL is declared as a date in your code.
    Please Login or Register  to view this content.
    Frob first, tweak later

  3. #3
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Macro to write custom function into cells

    post the entire function please

  4. #4
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Macro to write custom function into cells

    You need to use 'Set' here
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Macro to write custom function into cells

    Please Login or Register  to view this content.
    Is your Type Mismatch. You are passing a range to the UDF in the function.
    Please Login or Register  to view this content.
    There is so much wrong. I can debug it if you post the full UDF

  6. #6
    Registered User
    Join Date
    12-20-2006
    Posts
    11

    Re: Macro to write custom function into cells

    Neil, thanks for the replies. See whole function below:

    Please Login or Register  to view this content.
    Thanks,

    Rob

  7. #7
    Registered User
    Join Date
    12-20-2006
    Posts
    11

    Re: Macro to write custom function into cells

    Neil,

    Just playing around with this again. The problem seems to be when the IFERROR is true. Works ok (if probably a little inefficiently) when the hours function doesn't return an error

  8. #8
    Registered User
    Join Date
    12-20-2006
    Posts
    11

    Re: Macro to write custom function into cells

    Ok think I might have sorted this out.

    I've added "On Error Resume Next" on the first line of the function, it seems to run ok now.

+ 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] How do i write to cells in a function?
    By Turtleman10 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-28-2012, 11:01 AM
  2. Custom Function to read and write
    By ditzer252 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-21-2009, 10:06 AM
  3. Can I write a Macro into an IF Function?
    By FX42N in forum Excel General
    Replies: 1
    Last Post: 06-05-2006, 01:06 AM
  4. How to write a function or macro to copy
    By RandEman in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-24-2005, 03:45 PM
  5. how to write a macro for solver function
    By ernestgoh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2005, 01:22 PM
  6. write a function to determine if cells have names
    By andrewm in forum Excel Formulas & Functions
    Replies: 41
    Last Post: 09-06-2005, 07:05 AM
  7. Replies: 1
    Last Post: 08-16-2005, 02:05 PM
  8. How to either write the macro or manipulate the function
    By Beth in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2005, 06:07 PM

Tags for this Thread

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