+ Reply to Thread
Results 1 to 10 of 10

Comparing Dates With User-Defined Function

  1. #1
    Registered User
    Join Date
    08-28-2018
    Location
    Lexington, KY
    MS-Off Ver
    Office 365
    Posts
    14

    Comparing Dates With User-Defined Function

    I have (attempted) to create a function that will take a date as an argument, search for the number of occurrences of that date in a different sheet, increment a counter for each occurrence, and then return the counter. I keep getting 0 as the returned value.

    Function code:

    Please Login or Register  to view this content.
    day is assigned the cell that contains the date being searched for
    area is the name of the sheet I'm searching in
    area_range is the number of active rows in the sheet I'm searching in

    Example function call:

    =Misloads.xlsm!get_daily_misloads.get_daily_misloads(A2,"Day_Sort",day_sort_range)

    Active sheet:
    Active_Sheet.PNG

    Target Sheet:
    target_sheet.PNG

    I've been wrestling with this for FAR too long so any help would be most appreciated.

    Thanks

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Comparing Dates With User-Defined Function

    What happens if you step through the code and inspect the values in the IF statement condition? Are they the same? If not, how do they differ? Basic troubleshooting.

  3. #3
    Registered User
    Join Date
    08-28-2018
    Location
    Lexington, KY
    MS-Off Ver
    Office 365
    Posts
    14

    Re: Comparing Dates With User-Defined Function

    Quote Originally Posted by teylyn View Post
    What happens if you step through the code and inspect the values in the IF statement condition? Are they the same? If not, how do they differ? Basic troubleshooting.
    I'm not familiar with how to do that for a function.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Comparing Dates With User-Defined Function

    Make a test subroutine like
    Please Login or Register  to view this content.
    and then put a break point on the msgbox.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,925

    Re: Comparing Dates With User-Defined Function

    In this tutorial, I talk a little about debugging UDF's: https://www.excelforum.com/tips-and-...uild-udfs.html My approach is to add a Stop statement to the top of the UDF so that the code will stop and enter debug mode once I enter the function in the spreadsheet or trigger the UDF to calculate (by editing an input value, for example). It may take a few tries to find the best places for Stop statements so that I can quickly get to the real debugging, and they may need to move around as the process evolves. The key thing to learn is that you need to use Stop statements (or breakpoints) with UDFs in order to enter debug mode and debug what is happening.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Registered User
    Join Date
    08-28-2018
    Location
    Lexington, KY
    MS-Off Ver
    Office 365
    Posts
    14

    Re: Comparing Dates With User-Defined Function

    Ok. So, when debugging, I got this:

    error.PNG

  7. #7
    Registered User
    Join Date
    08-28-2018
    Location
    Lexington, KY
    MS-Off Ver
    Office 365
    Posts
    14

    Re: Comparing Dates With User-Defined Function

    Quote Originally Posted by MrShorty View Post
    In this tutorial, I talk a little about debugging UDF's: https://www.excelforum.com/tips-and-...uild-udfs.html My approach is to add a Stop statement to the top of the UDF so that the code will stop and enter debug mode once I enter the function in the spreadsheet or trigger the UDF to calculate (by editing an input value, for example). It may take a few tries to find the best places for Stop statements so that I can quickly get to the real debugging, and they may need to move around as the process evolves. The key thing to learn is that you need to use Stop statements (or breakpoints) with UDFs in order to enter debug mode and debug what is happening.
    I will check that out. Thanks

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,925

    Re: Comparing Dates With User-Defined Function

    From that watch list, what is in area? What is in i? Where was this at in the code (possibly before i had been assigned its first value, so that cells(nothing,9) has no meaning)?

  9. #9
    Registered User
    Join Date
    08-28-2018
    Location
    Lexington, KY
    MS-Off Ver
    Office 365
    Posts
    14

    Re: Comparing Dates With User-Defined Function

    I'm an idiot. I had the year set to 2019 in active sheet instead of 2018

  10. #10
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Comparing Dates With User-Defined Function

    There's a lot of that going around this time of year

+ 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] User Defined function for comparing 2 array and return approximate match
    By menonarun in forum Excel - New Users/Basics
    Replies: 9
    Last Post: 05-13-2018, 01:09 AM
  2. [SOLVED] User Defined Function to add dates
    By BlindAlley in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-15-2017, 10:18 AM
  3. Replies: 4
    Last Post: 02-17-2015, 08:15 AM
  4. [SOLVED] Chart by user defined dates
    By Ings in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 06-17-2013, 03:10 AM
  5. VBA to select cells based on user defined dates
    By rajkumarmp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2013, 07:09 AM
  6. Replies: 8
    Last Post: 05-19-2008, 05:11 AM
  7. [SOLVED] Excel - User Defined Function Error: This function takes no argume
    By BruceInCalgary in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2006, 04: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