+ Reply to Thread
Results 1 to 4 of 4

call a UDF in a sub

  1. #1
    Forum Contributor
    Join Date
    06-19-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Office365
    Posts
    273

    call a UDF in a sub

    Hello,

    I have a UDF as
    PHP Code: 
    Function LastDay(DateUsed As Date) As String
        
            LastDay 
    Format(CDate(WorksheetFunction.EoMonth(DateUsed0)), "dd-mm-yy")
      
        
    End Function 
    which returns the last day of a month given a date. I need to use it in a sub:
    Range("F13") = LastDay(Range("D6"))

    but instead of a date, I need cell D6 to show the function =LastDay(D6), can someone please help?

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: call a UDF in a sub


    Use the Formula Range property …

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: call a UDF in a sub

    My understanding is that a Function returns a value, i.e. a number or a string. I'm not aware it returns a format as well. Hence there seems little point in including a format in the function.
    And in any case you presumably want a proper date number returned to excel. In which case I'd be onclined to format the cells in Excel first. Then the function is

    Please Login or Register  to view this content.

    and in a procedure

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Contributor
    Join Date
    06-19-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Office365
    Posts
    273

    Re: call a UDF in a sub

    that is exactly what I need, thank you so much!!

+ 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. VBA: Put value in call
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2013, 07:51 AM
  2. Repeat call count for call center
    By arifmasum in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-08-2013, 10:03 PM
  3. How to set call count according to call date and time
    By naveen4pundir in forum Access Tables & Databases
    Replies: 0
    Last Post: 04-27-2012, 02:13 AM
  4. Call Sub
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-04-2009, 03:40 AM
  5. using CALL to call methods mandatory?
    By jerryliang2k in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2008, 06:16 PM
  6. call a sub
    By freddie mac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2007, 10:33 AM
  7. [SOLVED] Call Center Management: How to calculate 'cost per call'
    By Denniso6 in forum Excel General
    Replies: 2
    Last Post: 06-25-2006, 12:10 PM
  8. [SOLVED] Call
    By Edmund in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-16-2006, 12:50 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