Closed Thread
Results 1 to 5 of 5

Creating new rows and sorting

  1. #1
    Registered User
    Join Date
    08-22-2010
    Location
    Barre, VT
    MS-Off Ver
    Excel 2003
    Posts
    4

    Creating new rows and sorting

    Hi:

    I'm stuck in Excel. I don't have much VBA experience, so I was hoping someone here could help me. Currently in my spreadsheet, column Q represents industry types for stocks (say, aerospace/defense, banking, energy, oil, telecom, etc). I already have these stocks sorted by industry. What I'm trying to do is create a macro that will add two blank rows after the last stock in each industry has been listed. So, for example, if the column has:

    Banking
    Banking
    Banking
    Banking
    Oil
    Oil
    Energy
    Energy
    Energy

    each on an individual row, I would like to have the macro output it as:

    Banking
    Banking
    Banking
    Banking

    Oil
    Oil
    Oil

    Energy
    Energy
    Energy

    Pretty simple. Unfortunately, I lack the wherewithal to do it and there are about 4K stocks that I need to organize like this. Please help.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Creating new rows and sorting

    You can do it easily without VBA. First add a formula to an unused column:
    Please Login or Register  to view this content.
    The below that, list the numbers 1 to N twice:

    Please Login or Register  to view this content.
    The copy col B over itself as values, and sort everything by col B:

    Please Login or Register  to view this content.
    Then delete the uneeded column.

    It takes way more time to explain than do.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    08-22-2010
    Location
    Barre, VT
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Creating new rows and sorting

    So if I had 50 different sectors, I would have to assign each of the sectors a number like you did, and then after all that was done, I would have to go from 1 to 50 twice in column B?
    Last edited by shg; 08-22-2010 at 11:38 PM. Reason: deleted spurious quote

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Creating new rows and sorting

    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Creating new rows and sorting

    Please carry on in your cross-post.

    If you choose to carry on here, please acknowledge your understanding of our forum rules.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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