+ Reply to Thread
Results 1 to 30 of 30

My VBA Timestamp(X) function stop working when I add a tab to my workbook

  1. #1
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    My VBA Timestamp(X) function stop working when I add a tab to my workbook

    Hi,

    I am using this VBA function in my module 1 in the VBA :
    Please Login or Register  to view this content.
    So basically when someone enters a value in certain cell, the date is automatically written in a cell next to it.

    Everything works fine until I add a new tab, then, every date in my workbook is updated to the current date and I can't seem to correct this problem.

    Does anyone have an idea on how to solve this ?

    Best regards,
    Last edited by AliGW; 01-04-2022 at 11:31 AM. Reason: Code tags added.

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    So basically when someone enters a value in certain cell
    What certain cell...Same cells in all sheets...Only certain sheets????
    I would change this to a Workbook Sheet_Change Event
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    My excel workbook is keeping track of the material we order for each project, when someone orders a equipment and when the said equipment arrives, different dates are needed to keep track of all the material.

    What should I do differently if I wanted it to be a "Workbook Sheet_Change Event" ?

  4. #4
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    I am not sure that I understand correctly but as Now is volatile it is obvious.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    As per post 2
    What certain cell...Same cells in all sheets...Only certain sheets????
    Here is an example...Will give you an idea...
    Place this in ThisWorkBook Module
    When you enter anything in Range("A1:A20") of any sheet, the date will be entered into cell next to it...even when you add new tabs...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sintek; 01-04-2022 at 10:17 AM.

  6. #6
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    I invite you to take a look at my file.

    The columns and cells named "Date XXX" are the cell where the current date is applied automatically.

    Every yellow front cell is entered automatically depending on others cells in the workbook.

    Let me know if this is enough for you to understand my problem.

    Best regards
    Attached Files Attached Files

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    Make it easier for us...
    Your post 1 says...
    So basically when someone enters a value in certain cell, the date is automatically written in a cell next to it.
    What cells in which tabs do you enter data into that has to have the cell next to it populated with the Date

  8. #8
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    In every tab CX:

    -Write in B1, date in B2

    -Write in B4, date in B5

    -Write in GX, date in NX

    -Write in HX, IX, Jx or KX, date in OX

    -Dates from B5 in each CX tab are shown in the tab "Résumé commandes" in the cells P4, Q4, etc

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    This will give you an idea...Have only coded for B1 & B4

    I removed your Function...

  10. #10
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    This seems less versatile and more complicated for the not so different result.

    Is there a way to keep the Timestamp function while solving my problem ?

    Thanks for your time, this is appreciated

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    This seems less versatile and more complicated for the not so different result.
    Most certainly not...Welcome to the world of VBA...Gone are the days where you need to populate thousands of rows with formulas and functions for possible entries...

    With Function you are forced to enter the function formula manually in every cell etc etc etc
    With below code it all happens automatically as you enter values into the given ranges...

    This code below solves all required...

    -Write in B1, date in B2
    -Write in B4, date in B5
    -Write in GX, date in NX
    -Write in HX, IX, Jx or KX, date in OX
    Please Login or Register  to view this content.
    Try the file attached and see what I mean...
    Last edited by sintek; 01-04-2022 at 11:00 AM.

  12. #12
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    I have a couple questions:

    - Can we change it so the date updates If I remodify the cell the day after ?

    - Can we make it so if I erase the content of the cell, the date will disappear ?

    So basically that the date cell update with the content of its related cell

    ALso, I imagine that I could use "Today" instead on "Now" If I only need the date and not the exact time of the day ?

  13. #13
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    Using my file I attached...

    Can we change it so the date updates If I remodify the cell the day after ?
    The code already does that...

    Can we make it so if I erase the content of the cell, the date will disappear ?
    Red snippets amended...

    I could use "Today" instead on "Now"
    Yes...


    Please Login or Register  to view this content.
    Last edited by sintek; 01-04-2022 at 11:20 AM.

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,709

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. As you are still new here, I have done it for you this time.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  15. #15
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    It is working for the columns 7 to 11 but not for B1 and B4, I am not sure why though.

    Any idea ?

  16. #16
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    Does work for B1 and B4

    Untitled.png

  17. #17
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    I meant the date does not update if I erase B1, same thing for B4-B5

  18. #18
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    Get rid of your merged cells in rows...1 to 5...
    Excel's rule No 1 do not use merged cells...Causes havoc with VBA
    This snippet here bypasses the code if you want to clear more than one cell
    Please Login or Register  to view this content.
    With merged cells in those rows the count = 4 hence code is bypassed...

    Here is an alternative for Merged Cells and I have updated C1 accordingly which allows code to work perfectly...
    Last edited by sintek; 01-04-2022 at 12:11 PM.

  19. #19
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    All right, thank you very much for your patience et your time, I will try these out.

    Happy new year!

  20. #20
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    Pleasure...See post 18 update...

  21. #21
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    I forgot one question.

    Is there a way with my old version of the workbook to add tabs without losing my time stamps that I could use for my existing worbooks with dates that are already in since a couple months ?

    Basically back to my first question but only as a debug for my existing files so I don't lose all my info.

  22. #22
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    there a way with my old version of the workbook to add tabs without losing my time stamps
    I suggest updating your file with the new code and replace all previously entered time stamps formula with values...

    It is only range("B2,B5,N:O") of C# sheets...not so...

    Something like this...Then delete your function...Then add my code I supplied...This will then work all round....
    Please Login or Register  to view this content.
    If you don't come right upload your file and I will update it quickly...
    Please do replace those merged cells though...
    Last edited by sintek; 01-04-2022 at 02:27 PM.

  23. #23
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    Hi,

    I have two problems:

    1. I used the workbook this morning without doing any modification and the dates stopped working, they just dont appear automatically anymore. See for yourself.

    2. I tried your code for the already existing workbooks and it didnt work

    Best regards,
    Attached Files Attached Files

  24. #24
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    If it worked before then it should still work...Just tested ... All works as it should...
    remember to unprotect sheets!

    2. I tried your code for the already existing workbooks and it didnt work
    If you follow the steps above it should work perfectly...Cannot do anything to assist without seeing said workbook...
    Attached Files Attached Files
    Last edited by sintek; 01-06-2022 at 09:10 AM.

  25. #25
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    Is there a way to make it work while protecting the sheets ?

    Is there a setting that could be wrong on my part then ? I just tried to enter a number in the tab "C1" in the cell G7 and the date didnt appear in N7.

  26. #26
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    Is there a way to make it work while protecting the sheets ?
    Place this in the sheet module of sheets...
    Please Login or Register  to view this content.
    Just check if enableevents is true...Place this in a module and run
    Please Login or Register  to view this content.
    Should be True

  27. #27
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    What do you mean exactly by " in module of sheets " ? In a random module or in the "ThisWorkBook" file in VBA ?

    Also, why did you add this in the module 4 ?

    Sub t()


    Application.EnableEvents = True
    End Sub

  28. #28
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    I am assuming that an error occurred when trying to run code as the sheets were protected...
    This caused the code when firing not to complete...which did not turn on Enable Events
    Hence the code was not firing...
    I just turned on this event so that the code could fire...
    Change your workbook code to...
    Please Login or Register  to view this content.

    Also, why did you add this in the module 4 ?
    Please Login or Register  to view this content.
    Was just turning on the event
    Attached Files Attached Files
    Last edited by sintek; 01-06-2022 at 09:53 AM.

  29. #29
    Registered User
    Join Date
    05-26-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365
    Posts
    25

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    Great, this seems to work properly.

    Thanks again, you sir are a excel god lol

    Have a nice day, cheers.

  30. #30
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,204

    Re: My VBA Timestamp(X) function stop working when I add a tab to my workbook

    Most certainly not...Is as my Signature in Post 2 says...

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also...As you are fairly new here, you might not know that you can thank those who have helped by adding to their rep...Left of post...
    [* Add Reputation]

+ 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. Function InsertArrayFormula .SendKeys for large array formula stop working
    By stewegg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-13-2020, 01:43 AM
  2. [SOLVED] VBA scripts stop working after TimeStamp is used
    By mowens74 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-16-2019, 05:36 AM
  3. [SOLVED] If function stop working properly
    By lmcc007 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 08-28-2018, 06:48 PM
  4. [SOLVED] Want auto-gen number in template workbook to stop working when saved to normal workbook
    By tjamestx in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-24-2014, 02:56 PM
  5. Replies: 1
    Last Post: 10-30-2012, 07:10 AM
  6. Start and stop timestamp
    By Terriz in forum Excel General
    Replies: 3
    Last Post: 07-22-2009, 03:15 AM
  7. Shared Workbook caused Macro to stop working
    By Cresh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2009, 03:15 PM

Tags for this Thread

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