+ Reply to Thread
Results 1 to 11 of 11

Inserting header rows based on sorted column

  1. #1
    Registered User
    Join Date
    03-10-2021
    Location
    new york, usa
    MS-Off Ver
    2019
    Posts
    54

    Inserting header rows based on sorted column

    Hi

    Please see attachment. I have data in columns A:F. They are sorted by column A (smallest to largest). Is there a way to insert rows (of merged cells A:F) with numbers at the center that act as headers, and that indicate the beginning of the group of the numbers found in column A. For example:

    A2:F2 should say 1
    A5:F5 should say 2
    A11:F11 should say 3
    A18:F18 should say 5
    Etc?

    See sample in attachment. I placed the desired results in columns J:O. Preferably I would not want the formula to recreate the list a second time as in the sample. Rather, it should insert it in columns A:F

    Thank you
    Attached Files Attached Files

  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: Inserting header rows based on sorted column

    You could use Outline on the Data tab and insert a Subtotal (untick subtotals below). That would insert the rows you want. I think you'd need VBA to create the format that you want. Should be relatively straightforwatd based on the inserted subtotals.
    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
    03-10-2021
    Location
    new york, usa
    MS-Off Ver
    2019
    Posts
    54

    Re: Inserting header rows based on sorted column

    Thanks. The subtotal idea is helpful to insert the rows.
    As you said I’d probably need to get someone to write a VBA code to have it formatted the way I wanted.
    Thanks anyway.

  4. #4
    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: Inserting header rows based on sorted column

    VBA

    Please Login or Register  to view this content.

  5. #5
    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: Inserting header rows based on sorted column

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  6. #6
    Registered User
    Join Date
    03-10-2021
    Location
    new york, usa
    MS-Off Ver
    2019
    Posts
    54

    Re: Inserting header rows based on sorted column

    Thank you very much for working on this.

    I am embarrassed to say that I dont know how to put this code in the spreadsheet, and how to activate it once it is there.

    Can I bother you for quick instructions, or can you send me a spreadsheet with 5 columns and with the code in it so that i can just insert the data in it, and let me know how to activate it?

    Tyvm

  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: Inserting header rows based on sorted column

    Please see the updated sample workbook.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-10-2021
    Location
    new york, usa
    MS-Off Ver
    2019
    Posts
    54

    Re: Inserting header rows based on sorted column

    Hi TMS
    It works beautifully. Many thanks.
    Three requests please.
    1. can you move the buttons to the far right, around columns AD and AE.
    2. In case i add other columns (G, H, etc) with data, can the header rows also merge those columns accordingly?
    3. Most importantly, once the code generates the header rows with number, i dont really need column A which has the same numbers. But if i delete that column, then the information on the header also disappears. Can column A not be part of the merged cells in header? The merged cells should begin with column B.

    sorry for this extra work, and thanks again

  9. #9
    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: Inserting header rows based on sorted column

    Adjusted

    Please Login or Register  to view this content.
    Please note that the Reset Test Data was/is only intended for use during testing. I would suggest you delete it or, at least, don't use it once you add data.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    03-10-2021
    Location
    new york, usa
    MS-Off Ver
    2019
    Posts
    54

    Re: Inserting header rows based on sorted column

    perfect. Many thanks

  11. #11
    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: Inserting header rows based on sorted column

    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. VBA to Lookup all Rows based on Column Header
    By matt85webb in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-14-2018, 07:23 PM
  2. Delete Rows based on Column Header
    By eliasc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-17-2016, 10:19 AM
  3. [SOLVED] Summing Rows based on Column Header
    By HCLax in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-01-2015, 09:56 AM
  4. Replies: 4
    Last Post: 09-15-2014, 06:01 AM
  5. [SOLVED] Need Rows Sorted Into New Worksheets Based on Cell Value in Certain Column
    By jclaim in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-11-2014, 05:46 PM
  6. Inserting a new column w/new header name to the right of a certain header
    By hotwax in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-07-2013, 07:10 AM
  7. Inserting New Rows Based on Number in Column
    By althanis in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2010, 08:50 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