+ Reply to Thread
Results 1 to 2 of 2

VBA to Iterate Dates in Table Headers

  1. #1
    Registered User
    Join Date
    10-24-2016
    Location
    Bristol
    MS-Off Ver
    2010
    Posts
    2

    VBA to Iterate Dates in Table Headers

    Hi, thanks for any help. Im fairly experienced in excel but a novice with VBA.

    I have a workbook with multiple sheets each covering a financial year. Each sheet has several tables which have identical layouts and formula except that obviously the years are different. (Twelve columns with a header which is just "Apr-24", "May-24", etc.)

    It takes about 5 minutes to manually create a new year sheet by copying the previous year, and updating all the dates. This would need to be repeated for every workbook though so its a big job every year. I thought a VBA automation to iterate the year in a new sheet would be useful, but I'm having weird issues with it. This is the code:

    Please Login or Register  to view this content.
    This works for some dates some of the time but has really strange inconsistencies. For any year after 2000 it puts it to 2024. However if I manually change the date to 2031 it will then work correctly again up to 2099 before going back to 24. I would assume I've got something wrong in the loop where its still using data from the previous part, but I have no idea why that would only happen in a certain year range. I've tried a similar approach treating the headers as strings: "April-24" etc and if the rightmost 2 characters are an integer, adding one to it, and then updating the string - exactly the same result. Like there is something magic about 2024!

    Thanks so much for any pointers.

  2. #2
    Forum Contributor
    Join Date
    11-01-2024
    Location
    Korea
    MS-Off Ver
    M365 64bit v2411
    Posts
    254

    Re: VBA to Iterate Dates in Table Headers

    Please consider this sample.
    The format 'MMM/YY', it would be misunderstood as 'MMM/DD' at some years, i guess range as 2001~2031.
    Please Login or Register  to view this content.
    You made my day!

+ 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. pivot table from a data set with dates as column headers
    By genci in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 10-29-2024, 03:02 PM
  2. Replies: 2
    Last Post: 10-19-2024, 09:35 PM
  3. [SOLVED] Sum or Sumproduct or ? with dates in the table headers
    By blak9 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 10-04-2023, 07:37 AM
  4. [SOLVED] Iterate over Data Model Pivot Table
    By jrean042 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-02-2021, 04:55 PM
  5. autofilter method of range class failed -header has tables headers and non table headers
    By naveen.acheanz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-16-2016, 08:21 AM
  6. [SOLVED] How to copy across table headers that are dates?
    By 7:34pm in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 11-17-2015, 02:51 AM

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