+ Reply to Thread
Results 1 to 7 of 7

Change dates using Macro

  1. #1
    Forum Contributor
    Join Date
    02-20-2022
    Location
    Indonesia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Lightbulb Change dates using Macro

    Hi Guys,

    I currently work with the data that need to change the dates day by day/daily, I usually use CTR+H to replace the date.
    but I think there is a easier way to change it just by one click using macro code. (I'm using Office 2016)

    can you guys help me. I already attach the file

    Note: my data is daynow - 1 , so if today is 08 March 2022 in the data should be 07 March 2022

    hope you understand

    I also learn macro, but its kinda hard to learn by ourself without a friend or a mentor
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    01-07-2022
    Location
    Europe
    MS-Off Ver
    Office 365
    Posts
    473

    Re: Change dates using Macro

    not clear exactly where you want to update this date, but hopefully you can modify the below to suit your needs.

    - the code updates the value in cell D2
    - Now() -1 returns the current date/time less 1 day
    - the RoundDown function removes the time, to leave only the date

    Please Login or Register  to view this content.
    <<< If you have valued anyone's contributions in this thread, please click * to thank them for their efforts

  3. #3
    Forum Contributor
    Join Date
    02-20-2022
    Location
    Indonesia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Re: Change dates using Macro

    Sorry I dont explain that.

    I want to change in all active date. All dates in Row D automatically change

  4. #4
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Change dates using Macro

    The code assumed that in the beginning condition of the workbook is something like this :
    In column D starting from D2 to the last row with value, there is either empty row or row where the value will be only date ---> it doesn't matter what date they are.
    Example :
    D2 value 1 Nov 1964
    D3 value "blablabla"
    D4 to D7 empty
    D8 value 1 Jan 2019
    D9 value 5 Jul 2001
    D10 empty
    D11 empty
    D12 value 7 Mar 2022
    D13 empty
    D14 value 1 Dec 1964
    D15 value 8 Nov 2071
    .
    .
    .
    until the last row of column D value 17 Aug 1945.


    So when the workbook is open,
    the user see in column D (start from D8) like above.

    Now what the user want is, all those rows with date value is changed to yesterday date.
    So if the workbook is open on 13 Dec 2094, after the user run the macro,
    those rows with date in column D change to 12 Dec 2094.
    D2 value 12 Dec 2094
    D3 value "blablabla"
    D4 to D7 empty
    D8 value 12 Dec 2094
    D9 value 12 Dec 2094
    D10 empty
    D11 empty
    D12 value 12 Dec 2094
    D13 empty
    D14 value 12 Dec 2094
    D15 value 12 Dec 2094
    .
    .
    .
    until the last row of column D value is 12 Dec 2094.

    Please Login or Register  to view this content.
    Last edited by karmapala; 03-08-2022 at 12:00 AM.

  5. #5
    Forum Contributor
    Join Date
    02-20-2022
    Location
    Indonesia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Re: Change dates using Macro

    Quote Originally Posted by AskMeAboutExcel View Post
    not clear exactly where you want to update this date, but hopefully you can modify the below to suit your needs.

    - the code updates the value in cell D2
    - Now() -1 returns the current date/time less 1 day
    - the RoundDown function removes the time, to leave only the date

    Please Login or Register  to view this content.
    this is functional very well, but jud=st in row D2, I want run it in All cloumn with the date in it. Note, that that will empty and fill different column everyday.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Change dates using Macro

    Quote Originally Posted by Sultan1994 View Post
    Note: my data is daynow - 1 , so if today is 08 March 2022 in the data should be 07 March 2022
    try
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-20-2022
    Location
    Indonesia
    MS-Off Ver
    Excel 2016
    Posts
    103

    Re: Change dates using Macro

    Quote Originally Posted by jindon View Post
    try
    Please Login or Register  to view this content.
    this is work very well. I also add this first answer to fill my data in D2. thanks All

+ 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. Want to change the dates in selected cells manually using a MACRO
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2013, 03:22 AM
  2. Want to change the dates in selected cells manually using a MACRO
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-04-2013, 02:12 PM
  3. Macro to change the dates in header & footer for all Word documents
    By olga6542 in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2010, 05:39 PM
  4. change dates macro
    By superbob in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-18-2010, 07:13 AM
  5. Macro to change dates (while skipping weekends)
    By jchamber00 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2009, 04:31 PM
  6. Macro to change dates in Pivot table
    By EJOC in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-03-2009, 08:43 AM
  7. Macro to change dates in a selection
    By Slashy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2008, 07:48 PM
  8. macro w/dates that change
    By teiben in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-03-2007, 12:07 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