+ Reply to Thread
Results 1 to 25 of 25

auto fill date and time

  1. #1
    Registered User
    Join Date
    02-11-2014
    Location
    houghton regis bedfordshire england
    MS-Off Ver
    Excel 2010 soon to be 2016
    Posts
    47

    auto fill date and time

    Hi all

    I would like to enter data in cell a and i would like cell b to automatically enter the date and cell c enter the time.
    i would like this to do for rows 1 to 50
    can any one help i am a novice at excel vba

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: auto fill date and time

    Put this in the WORKSHEET code module

    Please Login or Register  to view this content.
    Last edited by AndyLitch; 02-11-2014 at 11:20 PM. Reason: Improved coding suggested by TM
    Elegant Simplicity............. Not Always

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,201

    Re: auto fill date and time

    @Andy: you need to switch off event handling if you are going to make a change in a Worksheet Change Event handler. And there are Date and Time variables that return the system date and time respectively, so you don't need to manipulate Now.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: auto fill date and time

    Thanks for that TM - I forgot about the positive feedback loop ... I shall amend the code accordingly

  5. #5
    Registered User
    Join Date
    02-11-2014
    Location
    houghton regis bedfordshire england
    MS-Off Ver
    Excel 2010 soon to be 2016
    Posts
    47

    Re: auto fill date and time

    i have cut and paste this in but nothing happens when i enter data in column a any idea what i am doing wrong ?

  6. #6
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: auto fill date and time

    Did you put it in the worksheet code module of the applicable worksheet ? It Has to be in the right worksheet module.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,201

    Re: auto fill date and time

    It's a worksheet change event and needs to go in the code module for the sheet. Right click on the sheet tab and select view code. Then paste the code there.

    Regards, TMS
    Last edited by TMS; 02-12-2014 at 07:06 AM.

  8. #8
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: auto fill date and time

    @andy, small issue, the second last line of your suggested code should be "= True" perhaps (having just fallen into the same issue myself on another project)

  9. #9
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: auto fill date and time

    Thanks for that JMac (damn this cut and paste LOL)

    Lloyd ... Recopy the code again ..... I accidentally disabled event trapping....

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,201

    Re: auto fill date and time

    @LLOYD6664: has your question been answered or do you need further help with this?



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  11. #11
    Registered User
    Join Date
    02-11-2014
    Location
    houghton regis bedfordshire england
    MS-Off Ver
    Excel 2010 soon to be 2016
    Posts
    47

    Re: auto fill date and time

    hI
    Dont know what i am doing wrong cut and paste into the worksheet code still cant get it to run
    i haave various coloumns when i enter Y into column b i want it to put date into column c and time into coumn d
    when i put Y into column E i want it to put time into column f etc. i have attached the sample file

    Can some eone please help im pulling my hair out here and i havent got that much left
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: auto fill date and time

    lloyd6664
    the code says that if you put something in a cell in colomn A, the date is placed in Col B and time in Col C as you requested...

  13. #13
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: auto fill date and time

    DBL post.....deleted.
    Last edited by nickmax1; 02-12-2014 at 01:24 PM. Reason: dbl post.

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,201

    Re: auto fill date and time

    The code in the sample workbook provided works fine. What are your macro security settings? Your profile says 2003 but this is a 2007+ workbook. Have you enabled macros?


    Regards, TMS

  15. #15
    Registered User
    Join Date
    02-03-2014
    Location
    CT
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: auto fill date and time

    Ive used this a function before by doing this and dragging the formatting down the 50 rows...
    For cells B =IF(A<>"",IF(B="",NOW(),B),"")
    and for Cells C =IF(A<>"",IF(C="",NOW(),C),"")
    Just be sure to format the cells with the date and time formats you want
    Last edited by Flee0723; 02-12-2014 at 02:09 PM.

  16. #16
    Registered User
    Join Date
    02-11-2014
    Location
    houghton regis bedfordshire england
    MS-Off Ver
    Excel 2010 soon to be 2016
    Posts
    47

    Re: auto fill date and time

    sorry nick

    forgot to add a couple of columns sstill cant get it working been trying for the last two hours is it possible to look at the
    spreaddsheet i attached and attach the code so i can see where i am going wrong.

  17. #17
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: auto fill date and time

    Book9.xlsm

    I would like to enter data in cell a and i would like cell b to automatically enter the date and cell c enter the time.
    Because the code was written to respond in changes to column A as initially specified... It therefore only worked on changes to column A but the actual requirement was to respond to column B changes.

    Another example of why uploading the workbook in the first instance is a good idea

    Can you mark this as eventually solved please
    Last edited by AndyLitch; 02-12-2014 at 06:08 PM.

  18. #18
    Registered User
    Join Date
    02-11-2014
    Location
    houghton regis bedfordshire england
    MS-Off Ver
    Excel 2010 soon to be 2016
    Posts
    47

    Re: auto fill date and time

    Sorry andy for the confusion i have downloaded the book9 and still doesnt do anything
    is there spmething on my machine which is preventing this do you know of anything ?

  19. #19
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: auto fill date and time

    Too many book 9's maybe...also make sure macro's are enabled....

    XYZ.xlsm
    Last edited by AndyLitch; 02-12-2014 at 07:15 PM.

  20. #20
    Registered User
    Join Date
    02-11-2014
    Location
    houghton regis bedfordshire england
    MS-Off Ver
    Excel 2010 soon to be 2016
    Posts
    47

    Re: auto fill date and time

    Thanks andy

    I really appreceiate your help i have downloaded the xyz file and tried to enter a y into the b column and nothing
    happened the date /time didnt seem to do anything i closed the file reopened it and nothing.
    this must be something to do with one of the settings i have no other files with this name can you suggest anyhting else
    that may prevent this working. ?

  21. #21
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,201

    Re: auto fill date and time

    What version of Excel are you using? Have you enabled macros in your security settings? When you open the workbook, does it ask you if you want enable macros? If it does, do you click OK?

    Regards, TMS

  22. #22
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: auto fill date and time

    Open this one and click the test button it should display a message and then fill in 10 rows of dates and times


    XYZ.xlsm

  23. #23
    Registered User
    Join Date
    02-11-2014
    Location
    houghton regis bedfordshire england
    MS-Off Ver
    Excel 2010 soon to be 2016
    Posts
    47

    Re: auto fill date and time

    Quote Originally Posted by TMShucks View Post
    What version of Excel are you using? Have you enabled macros in your security settings? When you open the workbook, does it ask you if you want enable macros? If it does, do you click OK?

    Regards, TMS
    I am running office 2007 i have enabled macros under the developer tab ?

  24. #24
    Registered User
    Join Date
    02-03-2014
    Location
    CT
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: auto fill date and time

    Book9autofill.xlsm
    Try this LLOYD

  25. #25
    Registered User
    Join Date
    02-11-2014
    Location
    houghton regis bedfordshire england
    MS-Off Ver
    Excel 2010 soon to be 2016
    Posts
    47

    Re: auto fill date and time

    Thank-you flee0723

    this works fine the only thing i need it do now is in column b if the contents are anything other than a "Y" it does not
    fill in the date and time when coloumn e contains a number between 1-84 it puts the time in F and lastly when a "Y" is put in column
    g that it puts the time in coumn h. can this be done in thee same code or do you need to have sheets as you can guess i am a complete new starter at the vba side of excel.

+ 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. auto fill-in current date/time and duration
    By aturetsky in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2013, 02:19 PM
  2. Auto Run Macro to fill and lock the date & Time
    By shaikh.2211 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-15-2012, 02:49 AM
  3. Auto fill Date + Double click (time stamp)
    By SVTF in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-05-2012, 03:29 PM
  4. Auto fill date/time
    By albert28 in forum Excel General
    Replies: 11
    Last Post: 07-27-2010, 08:31 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