+ Reply to Thread
Results 1 to 10 of 10

Columns and Data disappear when Macro finished running

  1. #1
    Registered User
    Join Date
    04-26-2023
    Location
    NY, NY
    MS-Off Ver
    Office 365
    Posts
    6

    Columns and Data disappear when Macro finished running

    Hi All,

    I created a macro where I go to the next sheet, insert five columns (A:D), add data on the inserted columns, and fix the column widths.

    Once the macro is completed, all the columns with data and formats are blank. Does any one know how to fix?

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Columns and Data disappear when Macro finished running

    Guessing your code doesn't do what you think it does, or does more than it should. You haven't shared the code or the workbook so, probably no-one here does know how to fix it.


    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    04-26-2023
    Location
    NY, NY
    MS-Off Ver
    Office 365
    Posts
    6

    Re: Columns and Data disappear when Macro finished running

    Please see the code below and let me know if this would help.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Columns and Data disappear when Macro finished running

    Running your posted code 'as is' .... it doesn't do anything except highlight a range on Sheet 2.

  5. #5
    Registered User
    Join Date
    04-26-2023
    Location
    NY, NY
    MS-Off Ver
    Office 365
    Posts
    6

    Re: Columns and Data disappear when Macro finished running

    I am adding 5 columns and adding data on row 5.

  6. #6
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Columns and Data disappear when Macro finished running

    Running the macro here, exactly as you have posted it in #3, doesn't do anything except highlight a range on Sheet 2.

    I won't be able to assist you because the macro does not work as you intended, on my computer. I don't know
    what else to say. Hopefully someone else can assist.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Columns and Data disappear when Macro finished running

    Your code does not change anything on the ActiveSheet. If it was blank beforehand, it would be blank afterwards (and vice versa).

    Your code selects whatever is the next sheet to the ActiveSheet and performs actions on it. It inserts five columns and adds headings and formatting on row five. If the last sheet in the workbook were selected before running this code, it would fail because there would be no next sheet. Because the last action relates to cell D5, that cell is left selected.

    I think using ActiveSheet.Next is poor programming as you cannot guarantee what the Active sheet is, let alone what the next sheet looks like.

    That said, it could be more efficient.


    My take on it:
    Please Login or Register  to view this content.
    Your code:
    Please Login or Register  to view this content.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Columns and Data disappear when Macro finished running

    Sorry, should have said, I'm not sure what output you expect. Your code does as you describe: goes to the next sheet, autofits all columns, inserts five columns, inserts headings on row five, and formats cell D5.

    The rest of the columns will be moved over. The new columns will be empty apart from the headings.

    My code does not select the sheet, nor any columns, nor any cells, so the Active sheet and the Active cell will remain unchanged.

  9. #9
    Registered User
    Join Date
    04-26-2023
    Location
    NY, NY
    MS-Off Ver
    Office 365
    Posts
    6

    Re: Columns and Data disappear when Macro finished running

    Thank you TMS. I was able to modify the macro for my needs.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Columns and Data disappear when Macro finished running

    You're welcome. Thanks for the rep.

+ 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: 5
    Last Post: 12-19-2014, 01:31 AM
  2. [SOLVED] Code to run a Macro when another macro has finished running
    By bouncingbudha in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-08-2014, 05:00 PM
  3. Data Validation Disappear in New Location after Running Advance Filter
    By Collinn in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-30-2012, 12:50 AM
  4. macro to input finished data into spreadsheet
    By imr1212 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2012, 04:39 PM
  5. [SOLVED] range names disappear when running a macro
    By dvb_24 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-11-2011, 05:03 AM
  6. Macro- Select Last Cell w/ Data When Finished
    By Tom K in forum Excel General
    Replies: 6
    Last Post: 01-08-2008, 03:28 PM
  7. [SOLVED] How to make userform disappear while called subroutine is running
    By Cornelia in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2006, 05:50 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