+ Reply to Thread
Results 1 to 12 of 12

VBA to add new year column after last column for all tables, and copy format & equations

  1. #1
    Forum Contributor daliye's Avatar
    Join Date
    05-28-2023
    Location
    North Africa
    MS-Off Ver
    microsoft excel, latest 365, 64-bit!
    Posts
    259

    VBA to add new year column after last column for all tables, and copy format & equations

    Hi,
    Current situation
    I've several tables within a sheet.
    Tables have different columns and rows regarding headers and contents.
    Some sheets have 10 tables and others have 30, so I can not determine the exact number of tables within the sheet.
    But all tables ending with a column contain a year number plus a word (this word changes from one table to another), the current table has "2016 Balance(Amount)", so other tables may have a different word, but always there is a year then a space, then the word which is "Balance(Amount)" in our example.
    Requirements
    From time to time I need to add a new column for a new year, so I go through all the tables manually and copy the last column for each table using the black small arrow that appears on the top of the column when you hover the mouse over the top of the first cell of the column, then press Ctrl+C to copy the entire column, then I press the right arrow then press Ctrl+V to paste formulas and format.
    So now the newly added column includes the last year's contents, so I do an extra step which is deleting the last year's contents which is associated with the column titled Amount/Equation "This column may be in a different place in another tables, but always will have the same header" where the cell in that row has the word "amount" and keep the contents if the cell has the word "equation".
    So the end result will be:
    • adding a new column.
    • copy only equations to the newly added column.
    • clear any other contents from the newly added column.
    • end result is: new column for the new year, only equations copied to that column, and all other contents get cleared from the newly added column.

    AddNewYearMacro.xlsx

    1.png

    2.png

    3.png

    4.png
    Last edited by daliye; 10-11-2023 at 06:49 AM. Reason: [SOLVED]
    thnx!
    d!
    microsoft excel, latest 365, 64-bit!

  2. #2
    Forum Contributor daliye's Avatar
    Join Date
    05-28-2023
    Location
    North Africa
    MS-Off Ver
    microsoft excel, latest 365, 64-bit!
    Posts
    259

    Re: VBA to add new year column after last column for all tables, and copy format & equatio

    Extra images for more details.

    5.png

    6.png

    7.png

  3. #3
    Forum Contributor daliye's Avatar
    Join Date
    05-28-2023
    Location
    North Africa
    MS-Off Ver
    microsoft excel, latest 365, 64-bit!
    Posts
    259

    Re: VBA to add new year column after last column for all tables, and copy format & equatio

    I hope someone may help.

  4. #4
    Forum Contributor daliye's Avatar
    Join Date
    05-28-2023
    Location
    North Africa
    MS-Off Ver
    microsoft excel, latest 365, 64-bit!
    Posts
    259

    Re: VBA to add new year column after last column for all tables, and copy format & equatio

    Somebody...Anybody
    simba.jpg

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

    Re: VBA to add new year column after last column for all tables, and copy format & equatio

    This will add a column only if the table has header named "Amount/Equation".
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor daliye's Avatar
    Join Date
    05-28-2023
    Location
    North Africa
    MS-Off Ver
    microsoft excel, latest 365, 64-bit!
    Posts
    259

    Re: VBA to add new year column after last column for all tables, and copy format & equatio

    Thanks a lot and much appreciated.

    I owe you, my friend.

    But I've realized that it adds a new column for tables in other sheets as well.
    Is it possible to add a column to the tables within the current sheet only? because I need this to be done within the current sheet only.
    Last edited by daliye; 10-11-2023 at 05:50 AM.

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

    Re: VBA to add new year column after last column for all tables, and copy format & equatio

    change to
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor daliye's Avatar
    Join Date
    05-28-2023
    Location
    North Africa
    MS-Off Ver
    microsoft excel, latest 365, 64-bit!
    Posts
    259

    Re: VBA to add new year column after last column for all tables, and copy format & equatio

    Excellent indeed!

  9. #9
    Forum Contributor daliye's Avatar
    Join Date
    05-28-2023
    Location
    North Africa
    MS-Off Ver
    microsoft excel, latest 365, 64-bit!
    Posts
    259

    Re: VBA to add new year column after last column for all tables, and copy format & equatio

    Today I've used this macro is a very critical issue at work, and I am blessed that you solved it.
    God bless you, my friend.
    Thanks a lot for everything.

  10. #10
    Forum Contributor daliye's Avatar
    Join Date
    05-28-2023
    Location
    North Africa
    MS-Off Ver
    microsoft excel, latest 365, 64-bit!
    Posts
    259

    Re: VBA to add new year column after last column for all tables, and copy format & equatio

    Hi,
    I've about 76 tables and the macro working as Sharpe.
    All formulas for all tables are copied forward to the newly added column with new references related to the newly added column.
    Please, some particular tables have somehow a complex formula as follows "other formulas look alike but still have the same concept":
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    When the new column is added after running the macro, the formula still
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    and not forwarded to next year, which should be
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    So does there is any adjustment that could be made to let it update the formula for the newly added column and include the new year?

    Note: When I drag the formula manually after running the macro, the formula is corrected but I can not guarantee that all other members will do the manual drag for these particular tables as I am not working alone in that file.
    So can the drag effect be done using VBA?

    AddNewYearMacro.xlsm

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

    Re: VBA to add new year column after last column for all tables, and copy format & equatio

    Is this how you wanted?
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor daliye's Avatar
    Join Date
    05-28-2023
    Location
    North Africa
    MS-Off Ver
    microsoft excel, latest 365, 64-bit!
    Posts
    259

    Re: VBA to add new year column after last column for all tables, and copy format & equatio

    Yes, it is exactly.
    Thanks a lot
    [SOLVED] ... Again!

+ 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. Replies: 9
    Last Post: 07-16-2018, 02:00 PM
  2. Copy data from Year Column to Date Column
    By Bobbbo in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-09-2017, 08:26 PM
  3. Copy a colum where add data in every year to another column
    By Shahadat65 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2015, 02:50 AM
  4. Replies: 7
    Last Post: 08-09-2015, 05:07 PM
  5. Replies: 0
    Last Post: 06-14-2013, 01:36 PM
  6. Match column between two sheets and copy row format once column number matches
    By kapil in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2010, 07:54 AM
  7. Rearranging tables into six-column format
    By The_YongGrand in forum Excel - New Users/Basics
    Replies: 10
    Last Post: 11-24-2009, 10:05 AM

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