+ Reply to Thread
Results 1 to 7 of 7

UDFs evaluating to #NAME

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    UDFs evaluating to #NAME

    I have a problem I cannot for the life of me work out why there is a problem.

    I have the following function.
    Function WhatYear(pdate As Date)
    'Application.Volatile
    Dim year_count As Integer
    Dim answer As Integer
    Dim date_start As Date
    Dim date_end As Date
    
    year_count = 1982
    answer = 0
    
    While answer = 0
        date_start = DateSerial(year_count, 4, 6)
        date_end = DateSerial(year_count + 1, 4, 5)
        If pdate >= date_start And pdate <= date_end Then
            WhatYear = year_count
            answer = 1
            Else
            year_count = year_count + 1
        End If
    Wend
    year_count = 1982
    answer = 0
    End Function
    It works out what tax year a date falls in. It has worked perfectly well. When it is downloaded from the net though it opens with the cell showing #NAME. If I use recalc or anything similar it doesn't change. The only way it comes up with an answer is if I edit and exit the cell. After that it works perfectly. Is there something wrong with this code? Or is it just something odd? TIA

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,060

    Re: UDFs evaluating to #NAME

    If you add the code after you already have a formula in place that uses it, you need to force a recalculation.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: UDFs evaluating to #NAME

    Rorya - The code was written then the formula used. It is now on downloading and reopening that the problem arises. How would I force a recalc using a piece of script?

    dominicb - that is kind of the problem. It works until it has been round the internet and back. Just wondered if there was soemthgin that wasn't technically correct in it that would cause the problem.

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: UDFs evaluating to #NAME

    Good afternoon malcmail

    I can't reproduce your problem - works perfectly for me.

    Would you be able to upload your workbook - you can get rid of most of the data, just leave a couple of dates to show as an example?

    HTH

    DominicB



    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitise the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Please familiarise yourself with the rules before posting. You can find them here.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,060

    Re: UDFs evaluating to #NAME

    Is the code in the same workbook as the formulas?

  6. #6
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: UDFs evaluating to #NAME

    It is. There's no duplication of UDF names, no modules named the same, no ranges named the same.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,060

    Re: UDFs evaluating to #NAME

    I'd suspect whoever used it previously disabled macros then. You could try calling either Application.CalculateFull or Application.CalculateFullRebuild in code, or if it's a small range or column/row of formulas, just use Find/Replace and replace = with = for those cells.

+ 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. Copying UDFs from another worksheet?
    By Scott S. in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-24-2011, 09:09 PM
  2. Where to put UDFs
    By BlairH in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-10-2010, 02:15 PM
  3. Udfs and Description
    By parm in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-13-2007, 06:16 AM
  4. UDFs in Excel
    By VBAnewbie in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-11-2006, 10:40 AM
  5. [SOLVED] how to access UDFs from a COM addin?
    By Steve Price in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2006, 04:45 AM
  6. UDFs Worksheet Level
    By Floyd Bates in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-14-2006, 10:35 AM
  7. Replacing UDFs with their value
    By Dave Moran in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-23-2006, 08:35 AM
  8. UDFs
    By DoctorG in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-05-2005, 09:05 AM

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