+ Reply to Thread
Results 1 to 18 of 18

cdate

  1. #1
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    cdate

    Im using the following code to convert text date to date format, but keep getting a type mismatch error, The date in text will look like 12/12/2012,
    Please Login or Register  to view this content.
    Can anyone help?

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

    Re: cdate

    datevalue and cdate both use your regional settings for converting date strings-do your regional settings specify the date format you have in the cells?
    Josie

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

  3. #3
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: cdate

    Probably c.Value is already a date.
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  4. #4
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: cdate

    They do match my regional settings and the date does look like a date but whenever I try to filter it doesnt give it as a month etc., as it can only see it as a text date & changing the cell format to date does not change the situation?

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

    Re: cdate

    no leading/trailing spaces?

  6. #6
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: cdate

    Change the line to
    Please Login or Register  to view this content.
    and see what happens.
    Last edited by Tsjallie; 08-19-2014 at 03:52 PM.

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: cdate

    Why not use the function identified in your subject?

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: cdate

    JosephP no leading or trailing spaces, Tsjallie, where should I which line should I change?

  9. #9
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: cdate

    Please attach a sample workbook.

    You will get an error if any cells in column A cannot be converted to a date. For example if the column header is "Date".
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  10. #10
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: cdate

    I have attached a sample workbook, In the example there is a header line which was no in my test but will be in the finished worksheet.
    Attached Files Attached Files

  11. #11
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: cdate

    Solus Rankin is right. The error comes from teh header.
    When you use column("A") row 1 is the forst row which contains a header text.
    Next row goes fine.

  12. #12
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Re: cdate

    The origina;l worksheet does not have a header and still does not work but in this case how can I get around the header issue?

  13. #13
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: cdate

    You can alter your code to skip row 1 line like this:
    Please Login or Register  to view this content.

  14. #14
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: cdate

    Here is some simple error trapping.
    Please Login or Register  to view this content.

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

    Re: cdate

    or simpler
    Please Login or Register  to view this content.

  16. #16
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: cdate

    Why covert a date to a date?

  17. #17
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: cdate

    @Tsjalie

    Look at workbook OP posted. They're in date format but stored as text.

  18. #18
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: cdate

    Why not just select the column, Data > Text to columns, Finish?
    Entia non sunt multiplicanda sine necessitate

+ 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. CDate not working
    By sglxl in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-01-2012, 08:14 AM
  2. CDate
    By blademaster3090 in forum Excel General
    Replies: 7
    Last Post: 01-17-2012, 08:15 PM
  3. [SOLVED] On error resume next and cdate problem
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2005, 10:05 AM
  4. CDate Problem
    By sil0000 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-22-2005, 03:24 AM
  5. CDate and IsDate
    By Geoff in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2005, 10:05 AM

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