+ Reply to Thread
Results 1 to 23 of 23

Permanent Date Stamp Macro

  1. #1
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Permanent Date Stamp Macro

    Hi Excel Forum!

    It's my first time posting on here because of a new job. I have a macro question that I hope you can help me with.

    I want a permanent date stamp to be recorded if a few criteria are met and the data is across two different sheets. Obviously I don't want the date to change as the Excel sheet is opened on another day.

    If B2(on page 1)= B2 (on page 2) AND C2="3" OR "9", THEN record TODAY() as a permanent date stamp, otherwise leave it blank " ". I know this isn't in Excel formula language but wanted to explain it in English. Let me know what other information is needed.

    Thank you very much for your help.

  2. #2
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Permanent Date Stamp Macro

    Hello welcome to the forum.

    Some basic code with your criteria would be:

    Please Login or Register  to view this content.
    You don't specify where you want the Date Stamp so here I've placed it in Sheet1 A1.

    DBY

  3. #3
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Re: Permanent Date Stamp Macro

    Thanks DBY. I realized I forgot to mention that. But I should be able to figure it out from your code. I'm gonna try it right now.

    Thanks for your help.

  4. #4
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Re: Permanent Date Stamp Macro

    ONe more question--I'm assuming this Macro is to be applied to the whole workbook and not just a particular sheet?

  5. #5
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Re: Permanent Date Stamp Macro

    It looks like it got caught on Sub DateStamp()

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Permanent Date Stamp Macro

    It looks like it got caught on Sub DateStamp()
    what does this mean?
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  7. #7
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Re: Permanent Date Stamp Macro

    The macro didn't work. The first line was highlighted which I believe means it didn't work....

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Permanent Date Stamp Macro

    What was the error message your received?

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Permanent Date Stamp Macro

    I tested DBY's code and it worked for me. Perhaps you need to post your spreadsheet to determine why it is not working for you.

  10. #10
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Re: Permanent Date Stamp Macro

    That would be great alansidman. How do I upload the spreadsheet?

  11. #11
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Permanent Date Stamp Macro

    Look at the attached picture, then click the reply button and you will get another button that says go advanced.

    Click the go advanced button.

    Do what it shows in the picture I attached.

    ViewPic
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  12. #12
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Re: Permanent Date Stamp Macro

    Ok, so I uploaded only the pertinent information for this macro since the rest is real and confidential.

    I want Column B in Product Data to populate the Date stamp when Column B in Contract Data is changed to 3 for example. So all of the "7's" in Product Data would have the permanent date stamp because 7 on Contract Data has a 3. The 9's in Product Data would just be left blank. I want it to be a macro so that the date doesn't change day to day. But I am curious what would the Excel formula be as well...this will help me understand how Excel works.

    If you have questions I'll try to answer.

    Thank you!
    Attached Files Attached Files

  13. #13
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Permanent Date Stamp Macro

    Any Excel formula you would use would change each time the date changes.

    The code I will give you puts the date into the cell at the point and time you change the cell to a 3.

    If you change the cell from 3 to say 7 on a different date, the date will remain as was, but will change again if the cell is changed back to a 3 again. I could also have it clear a cell if you change from a 3 to a different number.

    If this is not the behavior you want then you need to specify what you want to happen when.

    Another option is a button that runs a macro that checks all the cells when the macro is changed and puts the date in then, but maybe this isn't the behavior you want.

    Right click on the "Contract Data" tab and choose view code. Paste the code below into the white window.
    Save the file as a macro enabled type .xlsm, the macro will run whenever you change a value in the B column to 3.

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Re: Permanent Date Stamp Macro

    Skywriter,

    This is awesome! Thank you. I haven't tried it out yet because things have been busy. There also might be an added complication to the code but what you described is accurate to what I'm looking for. I'll be back on here soon to let you know how it works. Thanks again!

  15. #15
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Re: Permanent Date Stamp Macro

    It doesn't seem to be working quite right. Only one row with the value 7 got the date stamp and that was only after I changed the number in the Contract Data sheet from 3 to something else then back to 3. I'm looking for all of the "7's" to have a date stamp. In addition, other clients didn't get the date stamp even though their contract status was 3. See row 898 in product data for an example.

    In addition, row 78 with value 9 got a date stamp even though their contract status is NOT 3.

    Why is it behaving this way?

  16. #16
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Permanent Date Stamp Macro

    Well as far as row 78 I don't know without seeing it. As far as the other stuff I clearly pointed out how this works in my post #13, did you read it?

  17. #17
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Re: Permanent Date Stamp Macro

    Yes I did read it and it made sense. I just uploaded the xlsm file so you can take a look.

    Thank you for your help.
    Attached Files Attached Files

  18. #18
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Permanent Date Stamp Macro

    Maybe we're on a different page, so let me explain the code and make sure we're on the same page.

    Firstly the code is triggered by the worksheet change event for the "Contract Data" sheet. What this means is if you change any cell on that sheet the code is triggered. It will not be triggered if that change is the result of a formula. So if you are physically typing in a number in a cell then the code will be triggered.

    When the code is triggered the cell that was changed is what is called the target. You will see that in the code. I check that the target wasn't in row1 since you have headers, if it is you changed a header and we don't want to run the code.

    I check if the target was in column 2, which is what we want, it it's not in column 2, then again we don't want to run the code.

    Finally I check if you changed more than 1 cell. You can select a bunch of cells and type a number and hit control + enter and they will all change to that number. You don't want to do that with this sheet or the code won't run right because I wrote code that if you do this the code won't run. That is the Target.Count part you see in the code.


    So if all that checks out then the code checks if the target cell value was changed to 3. So the code checks what the cell was changed to.
    If this is the case then it goes to the same cell on the other sheet and puts a time stamp in that cell.

    So here is a scenario. You have a cell on contract data with a 3 already in it and a cell on the other sheet with a time stamp. You change the 3 to something else and the old time stamp stays. I can remove this if you want by simply changing the code to say if the number that changed on the contract data sheet is not a 3 then clear the same cell on the other sheet.

    The code is not made to run through your sheet and look for 3's and add a time stamp because that doesn't make sense to me. A time stamp is supposed to be when an event took place.

    If you want code that goes through every cell in the contract data at the push of a button then the question is how do we handle any cells that already had a time stamp on the first sheet. Replace them all, check if there is a time stamp in the cell already. I need to know what behavior you want to see and why.

    Knowing now how this works, I think maybe what you saw was perhaps because you didn't understand when the code was supposed to run and what is was supposed to do?

    If not, explain to me what you did and what happened so that I can recreate it.

  19. #19
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Re: Permanent Date Stamp Macro

    Ok, I see where the confusion is. I understand your explanation and the code describing the outer limits of the event procedure (when not to run it). The problem is, I don't want the same cell in Contract Data and Product Data to change..I want the date stamp for the given client ID. So in Contract Data...if rows 3, 67, 71, 78, 86, etc. change to a 3...I want the corresponding cells with the same client ID on the Products data page to get the date stamp. In this example that would be rows 2-35 for client ID 7, rows 603-606 for client ID 207, etc. You'll notice that some of the client ID's are missing..which is another question I have. Will the code be able to run if priorrecords are deleted POST date stamp. So for example, Row 35 on Product data gets date stamped and then 2 weeks later that record is deleted by our vendor...will the code still be able to run?

    I hope this makes sense.

  20. #20
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Permanent Date Stamp Macro

    So for example, Row 35 on Product data gets date stamped and then 2 weeks later that record is deleted by our vendor...will the code still be able to run?
    Remember the code runs based on you changing a value in "Contract Data" so whatever is deleted is deleted and whatever is not deleted is still there and untouched.

    So my question is are the client numbers on "Product Data" always contiguous like that?

    The reason I ask is it's much faster for me to write code that looks for the first 7 and then the last 7 and then it knows to time stamps those 2 cells and everything in between.

    If not, I have to loop every cell in that column and check its value.

  21. #21
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Re: Permanent Date Stamp Macro

    I think the vendor always sorts it by the client ID like that. But I'd love to see how to write it both ways just for learning purposes and so I can do it if it ever changes. For loops are something I want to learn.

    Thank you skywriter!

  22. #22
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Permanent Date Stamp Macro

    Both versions.

    Looping:
    Please Login or Register  to view this content.
    Range.Find:
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    12-14-2015
    Location
    Bellingham, WA
    MS-Off Ver
    2013
    Posts
    27

    Re: Permanent Date Stamp Macro

    Thanks Skywriter!

    This is awesome! I tried the For Next loop and when I enter a new value of "3" the code fires and a date stamp is produced. This is very exciting!

    I'm wondering if the code could fire without someone having to manually enter the value of 3? I believe those contract status codes are automatically produced from our system and not manually entered. Is this even possible?

    Anyway, thanks for your help Skywriter. I've learned a lot from this exercise.

+ 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] Permanent Time Stamp
    By anwaee2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-30-2014, 04:24 AM
  2. Permanent date stamp based on IF statement outcome
    By Darren6177 in forum Excel General
    Replies: 7
    Last Post: 05-09-2014, 04:30 PM
  3. Insert permanent Date & Time stamp if & when another cell is populated
    By valentino1989 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-24-2014, 10:15 AM
  4. [SOLVED] Insert permanent Date & Time stamp if & when another cell is populated
    By David_S_Walker in forum Excel General
    Replies: 6
    Last Post: 03-12-2014, 06:08 AM
  5. [SOLVED] Insert permanent Date & Time stamp if & when another cell is populated
    By BASELOO in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-18-2012, 02:27 PM
  6. Excel 2007 : Date stamp causes error in macro.
    By Nikeyg in forum Excel General
    Replies: 14
    Last Post: 04-12-2011, 11:54 AM
  7. Static Date Stamp without using a macro?
    By ride_op in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 03-30-2011, 08:46 PM

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