+ Reply to Thread
Results 1 to 15 of 15

Record Date and Time Macro

  1. #1
    Registered User
    Join Date
    06-02-2009
    Location
    Arlington, VA
    MS-Off Ver
    Excel 2007
    Posts
    80

    Record Date and Time Macro

    I have already looked at many of the posts but I have not found the solution that I am looking for. I am familiar with VB and the NOW function.
    I am trying to create a macro that will reference a cell and place a static date and time next to the cell. I want this date and time to only change when the checkbox is clicked.
    I have a checkbox in E11 that is linked to F11, I would like to have G11 record the date and time that the checkbox is clicked. I have already tried the following.

    Please Login or Register  to view this content.
    I would appreciate any help.
    Last edited by nsorden; 07-06-2009 at 04:34 PM.

  2. #2
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Record Date and Time Macro

    how about one with no macro?
    Attached Files Attached Files
    Regards
    Darren

    Update 12-Nov-2010 Still job hunting!

    If you are happy with the results, please add to our reputation by clicking the blue scales icon in the blue bar of the post.

    Learn something new each day, Embrace change do not fear it, evolve and do not become extinct!


  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Record Date and Time Macro

    I think you're working too hard. Put the code in the checkbox itself.

    Right-click on the checkbox and select VIEW CODE. Create a macro that looks like this:
    Please Login or Register  to view this content.
    You don't even need to link it to a cell.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    06-02-2009
    Location
    Arlington, VA
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Record Date and Time Macro

    I have many checkboxes...putting the code in each checkbox is not feasible.

    Also, the above solution suggests a formula that requires changing to iterative calculations. With the workbook shared and multiple formulas running I would not want to use that sort of calculation right?

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Record Date and Time Macro

    I don't use circular references, but they have their place. Up to you on whether they're acceptable or not.

    Going with your original approach, also feasible, it appears you want a timestamp in column G anytime a value in column F changes (caused by your checkboxes, yes?)...:
    Please Login or Register  to view this content.
    Adjust the red range to however much of column F you want to watch.

  6. #6
    Registered User
    Join Date
    06-02-2009
    Location
    Arlington, VA
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Record Date and Time Macro

    Please Login or Register  to view this content.
    Causes an error-Range of Object worksheet failed.
    It only does this when something is typed into the F column.
    It does not change when the checkbox is clicked.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Record Date and Time Macro

    Your syntax then:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-02-2009
    Location
    Arlington, VA
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Record Date and Time Macro

    Yes, that works fine if I type something into cell F10-> G10 records the date&time
    But, if the check box is linked to F10 and F10 changes from True to False...nothing happens.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Record Date and Time Macro

    Ah, didn't see that coming.

    Well, I did say not to do it that way. If the only reason you don't want to program the checkboxes is because there's so many of them, that's been faced before, too.

    Here's a link to a thread where an entire macro solution is offered to delete your existing checkboxes, put in new ones with their own macro. The new macro appears to effectively do the same thing your "linked" cells do, except the new replacement checkboxes do it in a way that triggers the worksheet_change macros.

    Have a look: (Dave Peterson's post)
    http://www.microsoft.com/communities...&cr=&sloc=&p=1

  10. #10
    Registered User
    Join Date
    06-02-2009
    Location
    Arlington, VA
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Record Date and Time Macro

    I keep running into an error in this part of the code:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-02-2009
    Location
    Arlington, VA
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Record Date and Time Macro

    Is there no way to just make a linked cell=Now and have that cell not change everytime the sheet recalculates? Why does this seem so impossible?

    This worksheet change event works when a cell is changed:
    Please Login or Register  to view this content.
    Isn't there some way to build this into the control options of the Checkbox click? Or assign a macro to make the now function carry over?

    If I were to just assign a macro to each checkbox how might I make the macro reference only the checkbox that was clicked(ie the one that triggers the macro)?

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Record Date and Time Macro

    Quote Originally Posted by nsorden View Post
    Is there no way to just make a linked cell=Now and have that cell not change everytime the sheet recalculates? Why does this seem so impossible?
    1) It's not impossible, I showed you a way to do that in post #3. You said "no".

    2) I showed you another way to do it just having changes in column F trigger a timestamp in post #7. You're need to use checkboxes without option 1) above means you've said "no" again.

    It's impossible because you discount working solutions.

    For me:
    I wouldn't use a "checkbox" to put a hidden value in a cell in an attempt to trigger a date in another column. I would put an "x" in column F and let the timestamp appear and move on.

    100s of checkboxes is a design nightmare...something I believe you've discovered for yourself.

  13. #13
    Registered User
    Join Date
    06-02-2009
    Location
    Arlington, VA
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Record Date and Time Macro

    1) It's not impossible, I showed you a way to do that in post #3. You said "no".
    Post #3 provided for only 1 checkbox and would not work for many check boxes

    2) I showed you another way to do it just having changes in column F trigger a timestamp in post #7. You're need to use checkboxes without option 1) above means you've said "no" again.
    The worksheet change event places a timestamp in the column when the cell is clicked. I have formulas that depend on that date and time. This means that if the cell is accidentally clicked by a user the date and time will populate, generating false results for other functions. This also did not work with the checkboxes-my original question.

    It's impossible because you discount working solutions.
    I am not discounting working solutions…I am just not getting the solution. I have been clear in my posts and have been willing to try all of the solutions.
    I have asked questions on how to solve the problems-but I have been pointed back to the same idea-post#3 each time-an idea which has not worked.

    For me:
    I wouldn't use a "checkbox" to put a hidden value in a cell in an attempt to trigger a date in another column. I would put an "x" in column F and let the timestamp appear and move on.
    As far as placing an X in F, as I stated above-that will return a value if clicked. I am trying to have the cell populate with a timestamp only when clicked. Placing an X, then deleting that X still results in a timestamp with the above solution.

    I have found the following code that makes 100s of checkboxes easy.
    Please Login or Register  to view this content.
    However, I still need a macro that will refer to the variable checkbox and run the macro-placing the timestamp in a variable cell location. This is what I have so farbut it returns an error "Compile error invalid or unqualified reference" at line 3.
    Please Login or Register  to view this content.

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Record Date and Time Macro

    I don't know a way to resolve all the issues the way you want. I would step back and look for an alternate route.

    For instance, we know the checkboxes can do their TRUE/FALSE thing in column F, no problem. And you want an unchanging timestamp in column G.

    So, what about formulas in column G like this, from G2 down:
    =IF(F2=TRUE,NOW(),"")

    Then, use a workbook_beforesave macro to scan column G and replace all values greater the "" with their own value. In the ThisWorkbook module:

    Please Login or Register  to view this content.
    Now, you don't have to fiddle with checkbox code at all.

  15. #15
    Registered User
    Join Date
    06-02-2009
    Location
    Arlington, VA
    MS-Off Ver
    Excel 2007
    Posts
    80

    Re: Record Date and Time Macro


+ 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