+ Reply to Thread
Results 1 to 14 of 14

Check cell format is Date or Time

  1. #1
    Registered User
    Join Date
    02-01-2017
    Location
    Lisboa
    MS-Off Ver
    2010
    Posts
    81

    Check cell format is Date or Time

    Hello,

    I am not an expert in VBA and I would appreciate some help with a problem I am trying to solve.

    I have a table where I have information of various products (A1:C14). I would like to insert a VBA code to automatically check if the information inserted in column B has the Date format (dd-mm-yyyy) and if the information inserted in column C has the Time format (hh:mm:ss), if the format is not the same the cell's fill colour should change to red.

    I adapted a code from the net, but the result is not the ideal, the blank cells also change the background to red.

    Any suggestions would be greatly appreciated

    Thank you in advanced.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Check cell format is Date or Time

    Hi Paul.

    Do you want the data checked as it is typed in or all at once.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    02-01-2017
    Location
    Lisboa
    MS-Off Ver
    2010
    Posts
    81

    Re: Check cell format is Date or Time

    Hi mehmetcik,

    The ideal solution is to have the data checked as it is typed in


    If the cell's fill colour change to red, the end users know that they made a mistake with the format of the inserted information.

    Best regards,

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Check cell format is Date or Time

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-01-2017
    Location
    Lisboa
    MS-Off Ver
    2010
    Posts
    81

    Re: Check cell format is Date or Time

    Hi mehmetcik,

    The vba seem to work fine in the "Date" format, but in the column of the "Time" format if I insert a text it gives me an error.

    Also, when I delete all the information of the cells they colour keep in red.

    Thank you for your help,

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Check cell format is Date or Time

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-01-2017
    Location
    Lisboa
    MS-Off Ver
    2010
    Posts
    81

    Re: Check cell format is Date or Time

    Hi mehmetcik,

    When I insert information in the "Date" column is tranformed to the hour format.

    In the column of the "Time" format if I insert a text (example: test) the cells do not changed to red.

    It is possible , when we delete all the information of the columns, to the red colour disappear ?

    Kind regards,

  8. #8
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Check cell format is Date or Time

    1. You need to delete the conditional formatting.

    2. Try this code:


    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-01-2017
    Location
    Lisboa
    MS-Off Ver
    2010
    Posts
    81

    Re: Check cell format is Date or Time

    Hi mehmetcik,

    I have tryed to delete the conditional formatting before testing the new code but is not working.

    Now the excel,starts to slow down and block, sometimes I select a row and it goes to another cell.

  10. #10
    Registered User
    Join Date
    02-01-2017
    Location
    Lisboa
    MS-Off Ver
    2010
    Posts
    81

    Re: Check cell format is Date or Time

    Hello mehmetcik,

    It is possible only to change the following code in order to ignore blank cells? If the cell is blank, the background colour not change to red.

    HTML Code: 

    Thank you for all your time and help.

  11. #11
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Check cell format is Date or Time

    This code is supposed to colour any blank cells white.

    Does it not do that for you?


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mehmetcik; 11-20-2020 at 06:43 PM.

  12. #12
    Registered User
    Join Date
    02-01-2017
    Location
    Lisboa
    MS-Off Ver
    2010
    Posts
    81

    Re: Check cell format is Date or Time

    Hi mehmetcik,

    I am sorry but when I tryed to insert information, the excel starts to slow down and block....for example when I insert information in cell B2 the excel blocks and goes to B3 or B4...something strange is happening.

    Instead of having a VBA code I am going try to insert the usual conditional formatting in the columns, the only problem Is that when the users do the "copy/paste" action, do not works.

    Best regards,

  13. #13
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Check cell format is Date or Time

    You could also use the Data Validation feature and have an alert message pop up if they didn't enter a date or time value within defined limits.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  14. #14
    Registered User
    Join Date
    02-01-2017
    Location
    Lisboa
    MS-Off Ver
    2010
    Posts
    81

    Re: Check cell format is Date or Time

    Hi mehmetcik,

    Yes I am going to use the Data Validation feature.
    This was my first ideia, but when I did the test to copy and paste I realized that it doesn't work (the message/alert does not appear in the scenario the user copy data with another format). Data validation is only checked if you write data manually (by user action). After reading some information on the net, I thougth the only way to overcome this problem was to create a vba code but I am not able to do it.

    Thank you for all the help.

+ 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] Converting Unusable Time / Date Format To Usable Time / Date Format
    By Gtrtim112 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-05-2019, 11:25 AM
  2. check for date in mixed text/date and format cell.. Help!
    By berbchid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-24-2013, 03:42 AM
  3. Replies: 4
    Last Post: 07-22-2013, 03:43 AM
  4. modify date time cell to an excel format date time
    By rileyp in forum Excel General
    Replies: 12
    Last Post: 03-24-2013, 08:39 PM
  5. Userform to check Date/Time format correct before copying to worksheet
    By LoneWolf3574 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-16-2013, 05:14 AM
  6. Replies: 1
    Last Post: 11-01-2012, 10:37 AM
  7. [SOLVED] Check IF a cell is a certain DATE format?
    By biddum in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-31-2012, 04:18 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