+ Reply to Thread
Results 1 to 5 of 5

Using "match" with dates - dates entered with vba return error

  1. #1
    Registered User
    Join Date
    04-27-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Using "match" with dates - dates entered with vba return error

    Hi there, I hope somebody can help.
    I have a function in an excel sheet which matches dates of the year (contained in column A) in the format dd/mm/yyyy with dates of bank holidays and staff holidays (entered in the same format), and uses the result to obtain a second value (the second value relates to whether it is a full day's holiday or a half day's holiday. It looks like this:

    INDIRECT("HOLIDAYS!C"&MATCH(A4,HOLIDAYS!$B$1:$B$100,0))

    The function works fine when the date of a holiday is entered manually, but when it is entered using a form it does not work and returns "#N/A".

    I have tried adding the date as a value; as text then formatting the relevant cells; using format(CDate(DateBox.Value),"dd/mm/yyyy") but none of them work, including when I reformat the relevant cells using Selection.NumberFormat = "dd/mm/yyyy".

    I'd be grateful for any advice as to how I might get over this problem without allowing users to have direct access to the relevant worksheet

    Thanks in advance

    Is

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Using "match" with dates - dates entered with vba return error

    don't use Format just use CDate
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    04-27-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Using "match" with dates - dates entered with vba return error

    Thanks for the reply Joseph. I'm afraid I've tried this as well but get the same error. I am guessing that one safe way around it would be to record all the dates in the spreadsheet in text format. While the dates currently look identical in the spreadsheet there is clearly a difference between those entered manually and those entered using a form, otherwise 'MATCH' would work fine. Does anyone have any suggestions about doing this.

    Thanks

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Using "match" with dates - dates entered with vba return error

    if your cell is formatted as date and you use CDate then you will get an actual date value in the cell. if the cell is formatted as text, you will get a text representation of a date. hard to say why the match doesn't work without seeing the workbook-it may also be that the values you are looking up against are not stored as dates.

  5. #5
    Registered User
    Join Date
    04-27-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Using "match" with dates - dates entered with vba return error

    I think I've solved it using the DateValue function. I did check all the dates and they were all formatted as dates so I can't say why CDate was not working.
    Thanks for your help Joseph.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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