+ Reply to Thread
Results 1 to 38 of 38

Column Addition and Deletion by VBA

  1. #1
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Column Addition and Deletion by VBA

    Hi guys,

    I have attached a spreadsheet, I'm creating a report. I would like to keep it on rolling 12 months. What I would like that every month when I enter the date at the top the following should happen automatically :

    1. Column 'B' removed
    2. Column 'C' to 'M' move from Column 'B'
    3. Column 'M' automatically add another Month

    I have attached the spreadsheet for your reference. Please can someone help me urgently as I need to submit the project by tomorrow.
    Attached Files Attached Files
    Last edited by abac; 02-07-2019 at 06:09 PM.

  2. #2
    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,888

    Re: Urgent help please

    Welcome to the forum! Please take a moment to re-read forum rule #1 and then amend your thread title to something that better explains your problem. Changing your thread title is not optional, which means you must change it. Thanks!

    Use concise, accurate thread titles.
    Your post title should describe your problem, not your anticipated solution.
    Use terms appropriate to a Google search - poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice tell us nothing.
    Responding to a request to change your thread title by doing so is mandatory.

    To change a title go to your first post, click EDIT then Go Advanced and change your title.

    No help to be offered, please, until the OP complies with this request.

    When you have changed the title, please also give full details of the problem in the body of your post - nobody should have to open an attachment to find out what you want.
    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

  3. #3
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Urgent help please

    Any one please help ?

  4. #4
    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,888

    Re: Urgent help please

    @abac
    No one will offer any help until you change the title in conformance with the Forum rules as noted in my earlier post.

  5. #5
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    Thanks Done !
    Can someone help please now.

  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,888

    Re: Column Addition and Deletion by VBA

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    Thank you for the response. But I really need help when I put date in like as I said in my original message

    1. Column 'B' removed
    2. Column 'C' to 'M' move to Column 'B'
    3. Column 'M' automatically add another Month

  8. #8
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Column Addition and Deletion by VBA

    The easiest method for this is to have an underlying table that keep more than 12 months where you add new values and have your value

    In attached sheet test rolling 12 month with in K2 put 1-1-2019, 1-2-2019 or 1-3-2019 to see the data "roll" forward

    the data is controlled by basicly 1 offset formula that moves based on selected date.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    Thank you Roel - but it only changes the month but doesn't change the data underneath ? please can you have a look and also can you copy the formula here so I can put it in the original spreadsheet.

    Thank you so much once again.

  10. #10
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    anyone please help ????

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

    Re: Column Addition and Deletion by VBA

    Do you mean?
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    hi I have attached the spreadsheet and shows exactly what I want. I have highlighted in colours and put next to it to make it easier. Please help. Thank you
    Attached Files Attached Files

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

    Re: Column Addition and Deletion by VBA

    Not clear to me.

    Can you upload 2 sheets showing before/after and the logic?

  14. #14
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    sure i have done it before or after
    Attached Files Attached Files

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

    Re: Column Addition and Deletion by VBA

    See if this is how you wanted,
    Run the code on the file you uploaded in your post #12, not the latest one.
    Please Login or Register  to view this content.
    ...I think I misread the question...
    Last edited by jindon; 02-07-2019 at 09:29 PM.

  16. #16
    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,888

    Re: Column Addition and Deletion by VBA

    Rule 03: Cross-posting Without Telling Us

    Your post does not comply with Rule 3 of our Forum RULES. Do not cross-post your question on multiple forums without telling us about your threads on other forums.

    Post a link to any other forums where you have asked the same question. If you have fewer than 10 posts here, you will not be able to post a link, but you must still tell us where else you have asked the question.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    If you have less than 10 posts, do not try to copy and paste the link. Instead, type the link out in your thread.

    No further help to be offered, please, until the OP has complied with this request.

  17. #17
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Column Addition and Deletion by VBA

    It was late last night..
    I did not save the final version so the intended formula was only in the first cell

    have a look at this one..

  18. #18
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Column Addition and Deletion by VBA

    We advise you not to 'bump' (reply to) your own posts too quickly after posting, unless you are posting some sort of clarification. If you do bump, limit it to no more than once every day. Remember that your best helper may be asleep on the other side of the world.

  19. #19
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    Hi Admin,
    I'm so sorry I didn't know about the rule. However I do know now and will be careful going forward. I have only posted the same question on the following forum :
    https://www.mrexcel.com/forum/excel-...umns-help.html

    Please can you unblock the replies from expert so I can get help. I'm happy to remove the question from that forum if required.

    Many thanks
    Abac

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

    Re: Column Addition and Deletion by VBA

    This is to copy 12 months of data from Data history sheet, only when the date in K2 match to the column or beyond until the data exists.

    What I mean is that when you enter 2018/12/1, it will not change due to 2018/21/1 back 11 month is Jan, but you only have from Feb.
    Also if the data in K2 exceeds the max of date in Data history sheet, it will not change.

    So in you attached workbook,it only updates if the date in K2 is 2019/1/1 to March.
    To Report view sheet code module
    Please Login or Register  to view this content.
    Forgot to mention:
    You need to change the formula in Row 5 to value like attached
    Attached Files Attached Files
    Last edited by jindon; 02-08-2019 at 06:05 AM.

  21. #21
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    Hi Admin,
    please can you unblock the post after Post #16 from Roel Jongman as well.
    Thank you

  22. #22
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Column Addition and Deletion by VBA

    Hi abac,

    the hiding and unhiding of my post deleted the attachment.

    SO I repost it here.
    Attached Files Attached Files

  23. #23
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    Thanks a lot Roel and Jindon

    Is there anyway not to have data history sheet completely and just on the front sheet - as soon as you put the month, automatically all other months moves on to left and keep one blank column with the new month to update data in there manually.
    Thank you

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

    Re: Column Addition and Deletion by VBA

    What are the dates you enter in K2?
    Is it always greater than M5?

  25. #25
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    Hi Jindon,
    Dates in M6 is always the same month as K2. So if I put in K2 01/02/2019 then in M5 it should show Feb.
    thank you

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

    Re: Column Addition and Deletion by VBA

    Then what's wrong with the code I posted in #15?

  27. #27
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    Sorry jindon - i'm not sure if I'm doing something wrong or not explaining it properly. So I will do it step by step of what I need help with :

    1. Remove Data History sheet - as this won't be in any use
    2. On the main sheet - when I put the date in K2
    3. All the data from C5 to M9 shifts to the left
    4. Starts from B5 to L9
    5. Column M5 to M9 becomes blank with the same month in K2, so I can enter the current month data.

    The above will show the 12 months rolling data and every month when I put the new month data then automatically new month appears in column M5.

    Hope it makes sense. Thank you so much for taking time out to help me. I really appreciate that.

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

    Re: Column Addition and Deletion by VBA

    If you want when K2 entered one month more than the date in M5, means 2019/2/1 in you attachment.
    Next when you change K2 to 2019/3/1, it adds one month.

    As I mentioned already, formula in row 5 must be converted to the date.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  29. #29
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Column Addition and Deletion by VBA

    I get what you want just went another route with data history as I often use that because I like it when I can also go back a few months.. but we are not here to solve my problems

    So with a macro.. try this

    Please Login or Register  to view this content.
    Attached Files Attached Files

  30. #30
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    Thank you Jindon and Roel - you guys absolutely genius. I owe you one
    Just one last question @Jindon - is it possible to put any date to make the change to happen rather than just 1st of each month - so for example if I put 28/01/2019 I want the same action to happen ?

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

    Re: Column Addition and Deletion by VBA

    Do you mean like this?
    Please Login or Register  to view this content.

  32. #32
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    absolutely genius - thank you so much. I owe you one.

    Just last question, how it's doing it in M5 if I want the same action to be done in M16 and M27, what shall I do ?

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

    Re: Column Addition and Deletion by VBA

    You need to clear all your comment in row 4.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  34. #34
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    Thank you so much,
    could you kindly put the same formula to the attached spreadsheet as well.
    Attached Files Attached Files

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

    Re: Column Addition and Deletion by VBA

    Now your file is different.

    What is this?
    What do you mean by formula?

    What are you really trying to do?

  36. #36
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    Hi Jindon,
    In the Post 33 script can you please put the same VBA script in the post 34 file. I'm trying to create 2 database and both are similar.
    I promise this is the last request and no more trouble for you.
    Thank you

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

    Re: Column Addition and Deletion by VBA

    For the latest workbook.
    Please Login or Register  to view this content.

  38. #38
    Registered User
    Join Date
    01-18-2019
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    87

    Re: Column Addition and Deletion by VBA

    Thank you so much Jindon - really appreciate your help

+ 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. [URGENT][Help with a VBA Macro - Maximum with criterias][URGENT]
    By mahmoudmerhi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2013, 03:39 PM
  2. Need urgent help with error! Urgent!
    By heidenman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-03-2009, 04:31 AM
  3. Need Help Urgent Please !!!
    By ogniand in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-19-2008, 11:31 AM
  4. Urgent Help!
    By mard in forum Excel General
    Replies: 1
    Last Post: 11-15-2008, 06:24 PM
  5. Urgent help thanks!
    By max_1999 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2008, 07:26 AM
  6. Urgent-Urgent VBA LOOP
    By Jeff in forum Excel General
    Replies: 0
    Last Post: 10-06-2005, 01:05 PM
  7. *URGENT*
    By Stacy in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  8. [SOLVED] Not Urgent
    By Gary's Student in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-26-2005, 05:05 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